栈与队列的顺序存储结构及实现C++语言源程序实验二 栈和队列 一、实验目的 1. 掌握栈这种数据结构特性及其主要存储结构,并能在现实生活中灵活运用 2. 掌握队列这种数据结构特性及其主要存储结构,并能在现实生活中灵活运用 二、栈和队列的顺序存储结构 在教材中,我们给出了栈的链表存储结构和队列的链表存储结构及实现,下面给出的是栈的顺序存储结构及实现和队列的顺序存储结构及实现 1.栈的顺序存储结构及实现C++语言源程序 //--------------------------------------------------------------------------- //栈的顺序存储结构,顺序表类 #include //------------------------------栈的顺序存储结构--------------------------------------------- typedef int ElemType; // 数据元素的类型为int const int MAXSIZE=100; // 数组的容量 class SqStack { private: ElemType elem[MAXSIZE]; int top; public: SqStack( void); ~SqStack{}; int SqStack::SetEmpty; void SqStack::push( ElemType e); ElemType SqStack::pop; void SqStack::PrintOut; int SqStack::IsEmpty(void)const ; }; //------------------------------------------------------------- SqStack::SqStack( void):top(0){ } int SqStack::SetEmpty { return top==0; } void SqStack::push( ElemType e) { if(top==MAXSIZE-1) cout<<"\n栈满溢出"<=1;k--) cout<>k; switch(k){ case 1:{cout<<"\n 入栈,数据 e=?"; cin>>e; as.push(e); as.PrintOut; }break; case 2:{ cout<<"\n 出栈"; x=as.pop; cout<<"\n 出栈元素数值= "<=1&&k<3); cout<<"\n 再见!"; cout<<"\n 按任意键,返回。
"; return 0; } 2.队列的顺序存储结构及实现C++语言源程序 //--------------------------------------------------------------------------- #include #define MAXSIZE 20 typedef int ElemType; class SeQueue { private: ElemType elem[MAXSIZE]; int front,rear; public: SeQueue; ~SeQueue; void Display; void AddQ(ElemType x); ElemType DelQ; }; SeQueue::SeQueue { front=0; rear=0; cout<<"init!"<>k; switch(k){ case 1:{SeQueue::SeQueue; }break; case 2:{h.Display; }break; case 3:{ cout<< "进队 data=?"; cin>>e; h.AddQ(e); h.Display; }break; case 4:{ e=h.DelQ; if(e!=-1) cout<< "出队的结点值是:"<=1&&k<5); cout<<"\n 再见!"; cout<<"\n 按任意键,返回。
"; return 0; } 三、实验结果 别太lan,自己跑起来!动手截图吧! 四、总结 软件设计与实现过程种的经验与体会,进一步的改进设想,可再加入哪些部分?哪些部分可删除?哪些部分。