1. 实验1栈和队列的实现和应用实验目的熟练掌握栈、队列的建立方法;熟练掌握栈和队列基本操作;栈和队列的实例应用实验内容1.选用一种存储结构建立栈、队列栈的应用:Adeskcalculation(教科书P66)队列验证:Menu-drivendemonstration(教科书上P93)实验结果总结算法应用和结构优缺点栈:#includeusingnamespacestd;constintmaxstack=100;enumError_code{success=1,overflow=-1,underflow=-1};typedefintStack_entry;classStack{public:Stack(){count=0;}boolempty();Error_codepop();Error_codetop(Stack_entry&item);Error_codepush(constStack_entry&item);intsize();private:intcount;Stack_entryentry[maxstack];};Error_codeStack::push(constStack_entry&item){Error_codeoutcome=success;if(count>=maxstack){outcome=overflow;}else{entry[count++]=item;}returnoutcome;}Error_codeStack::pop(){Error_codeoutcome=success;if(count==maxstack){outcome=underflow;}else{count--;}returnoutcome;}Error_codeStack::top(Stack_entry&item){Error_codeoutcome=success;if(count==0){outcome=underflow;}else{item=entry[count-1];}returnoutcome;}boolStack::empty(){booloutcome=true;if(count>0){outcome=false;}returnoutcome;}intStack::size(){returncount;}intmain(){Stacknumbers;for(inti=0;i<10;i++){numbers.push(i);}intv;while(!numbers.empty()){numbers.top(v);cout<executIontime:0.016sPressanukeytocontinue-队列:#includeusingnamespacestd;constintmaxqueue=100;enumError_code{success=1,overflow=-1,underflow=-1};typedefintQueue_entry;classQueue{public:Queue(){count=0;rear=maxqueue-1;front=0;}boolempty();Error_codeserve();Error_coderetrieve(Queue_entry&item);Error_codeappend(constQueue_entry&item);intsize();private:intcount;intfront,rear;Queue_entryentry[maxqueue];};Error_codeQueue::serve(){Error_codeoutcome=success;if(count<=0){returnunderflow;}count--;front=((front+1)==maxqueue)?0:(front+1);returnsuccess;}Error_codeQueue::append(constQueue_entry&item){Error_codeoutcome=success;if(count>=maxqueue){returnoverflow;}count++;rear=((rear+1)==maxqueue)?0:(rear+1);entry[rear]=item;returnsuccess;}Error_codeQueue::retrieve(Queue_entry&item){if(count<=0){returnunderflow;}item=entry[front];returnsuccess;}boolQueue::empty(){returncount==0;}intQueue::size(){returncount;}intmain(){Queueq;for(inti=0;i<10;i++){q.append(i);intv;while(!q.empty()){q.retrieve(v);cout<executiontime:063sPresstocontinue.栈的应用:逆波兰计算器#includeusingnamespacestd;constintmaxstack=100;enumError_code{success=1,overflow=-1,underflow=-1};typedefdoubleStack_entry;classStack{public:Stack(){count=0;}boolempty();Error_codepop();Error_codetop(Stack_entry&v);Error_codepush(constStack_entry&v);intsize();private:intcount;Stack_entryentry[maxstack];};Error_codeStack::push(constStack_entry&v){Error_codeoutcome=success;if(count>=maxstack){outcome=overflow;}else{entry[count++]=v;}returnoutcome;}Error_codeStack::pop(){Error_codeoutcome=success;if(count==maxstack){outcome=underflow;}else{count--;}returnoutcome;}Error_codeStack::top(Stack_entry&v){Error_codeoutcome=success;if(count==0){outcome=underflow;}else{v=entry[count-1];}returnoutcome;}boolStack::empty(){booloutcome=true;if(count>0){outcome=false;}returnoutcome;}intStack::size(){returncount;Stacks;charget_command(){charx;boolwaiting=true;while(waiting){cin>>x;x=tolower(x);if(x=='?'||x=='='||x=='+'||x=='-'||x=='*'||x=='/'||x=='q'){waiting=false;}else{cout<<"Pleaseenteravalidcommand:"<>p;s.push(p);break;case'=':if(s.top(p)==underflow){cout<<"Stackempty."<usingnamespacestd;constintmaxqueue=100;enumError_code{success=1,overflow=-1,underflow=-1};typedefintQueue_entry;classQueue{public:Queue(){count=0;rear=maxqueue-1;front=0;}boolempty();Error_codeserve();Error_coderetrieve(Queue_entry&v);Error_codeappend(constQueue_entry&v);intsize();voidclear(){count=0;rear=maxqueue-1;front=0;}private:intcount;intfront,rear;Queue_entryentry[maxqueue];};Error_codeQueue::serve(){Error_codeoutcome=success;if(count<=0){returnunderflow;}count--;front=((front+1)==maxqueue)?0:(front+1);returnsuccess;}Error_codeQueue::append(constQueue_entry&v){Error_codeoutcome=success;if(count>=maxqueue){returnoverflow;}count++;。