欢迎来到天天文库
浏览记录
ID:46391392
大小:72.00 KB
页数:5页
时间:2019-11-23
《C++用数组实现栈》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#includeusingnamespacestd;constintMaxStatckSize=100;//栈大小classMYStack{private:intstacklist[MaxStatckSize];inttop;//栈顶public://构造函数MYStack(void);~MYStack(void);public://压栈出栈操作voidPush(constint&item);intPop(void);voidClearStack(void);//访问栈顶intPeek(void)const;//检测椎栈boolisEmpty(void)const
2、;boolisFull(void)const;};MYStack::MYStack(void){this->top=-1;}MYStack::~MYStack(void){this->top=-1;}voidMYStack::Push(constint&item){//栈是否已满if(!isFull()){top+=1;this->stacklist[top]=item;}elsestd::cout<<"OutoftheStack!"<3、acklist[ebp];}elsereturn-1;}intMYStack::Peek(void)const{returntop;}voidMYStack::ClearStack(){for(inti=top;i>=0;i--)stacklist[i]=0;top=-1;std::cout<<"Clearstackdone!"<MaxStatckSize?true:false;}boolMYStack::isEmpty(void)const{returntop<0?true:f4、alse;}intmain(){MYStackm1=MYStack();MYStackm2=MYStack();intk,l;while(cin>>k>>l){if(k==1)m1.Push(l);if(k==2)m2.Push(l);}intou1,ou2;ou1=m1.Pop();while(ou1!=-1){cout<
3、acklist[ebp];}elsereturn-1;}intMYStack::Peek(void)const{returntop;}voidMYStack::ClearStack(){for(inti=top;i>=0;i--)stacklist[i]=0;top=-1;std::cout<<"Clearstackdone!"<MaxStatckSize?true:false;}boolMYStack::isEmpty(void)const{returntop<0?true:f
4、alse;}intmain(){MYStackm1=MYStack();MYStackm2=MYStack();intk,l;while(cin>>k>>l){if(k==1)m1.Push(l);if(k==2)m2.Push(l);}intou1,ou2;ou1=m1.Pop();while(ou1!=-1){cout<
此文档下载收益归作者所有