{ cout< int DuSqStackPop(DuSqStack &S,SElemType &x) { //S is a shared stack //this function will pop the top element //from S.top1 or S.top2 by x cout< 25 into DuSqStack }//end of if else {cout<<\ return(0); } break; case 2: if(S.top2 }//end of DuSqStackPop() function void main() //main() function { DuSqStack S; SElemType x=2000; //push x into DuSqStack S cout<<\ InitDuSqStack(S); //To Initilaize DuSqStack DuSqStackPush(S,x); //Test DuSqStackPush function twice DuSqStackPush(S,x); //for example to push two element into DuSqStack DuSqStackPop(S,x); //Test DuSqStackPop function //and return by x getch(); } 26 10、实现由一定通用性的程序,实现一个四则运算表达式的求解 #include #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 typedef int SElemType ; typedef struct SqStack { SElemType *base; SElemType *top; int stacksize; }SqStack; int InitStack(SqStack &S) //InitStack() subfunction { //constructe a empty stack S.base=(SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType)); if(!S.base) { cout<<\ return (0); } S.top =S.base ; S.stacksize =STACK_INIT_SIZE; cout<<\ return (1); }//end of InitStack() function int Push(SqStack &S,SElemType e) //Push() subfunction { //Push element to SqStack if(S.top-S.base >S.stacksize) //Stack == full? 27 { S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT*sizeof(SElemType))); if(!S.base) { cout<<\ return(0); } S.top=S.base+S.stacksize; //To modify pointer of Stack top S.stacksize+=STACKINCREMENT; //To modify the size of stack } //end of if *S.top++=e; //S.top++ and push e into stack S return (1); }//end of Push() subfunction int StackEmpty(SqStack &S) //StackEmpty() function { //judge empty stack ? if(S.top==S.base) return(1); //empty return 1 else return(0); } int Pop(SqStack &S,SElemType &e) { //if empty(S) then Error,otherwise Delete the S.top element //and return it by variable e if(S.top==S.base) { cout<<\ return (0); } e=*--S.top; //S.top-- and assign the values to e return(1); } void Conversion() //Conversion() function { SqStack S; //S is a SqStack SElemType N,e; InitStack(S); //constructe a empty stack S printf(\ scanf(\ while(N) { Push(S,N%8); N=N/8; } printf(\ while(!StackEmpty(S)) //no empty then output { Pop(S,e); 28 printf(\ } }//end of conversion() function void main() //main() function { cout<<\ Conversion(); cout< }//end of main() 【实验结果】 1、写出实验的总结与体会,要简洁、真实、深刻;忌空话、套话 29
中北大学 算法与数据结构实验报告(6)
2019-04-23 22:43
中北大学 算法与数据结构实验报告(6).doc
将本文的Word文档下载到电脑
下载失败或者文档不完整,请联系客服人员解决!