数据结构实验二顺序队列

#include<iostream.h>
const int StackSize=100;
template<class DataType>
class SeqStack
{public:
SeqStack(){top=-1;}
~SeqStack(){}
void Push(DataType x){if((top+1)==100) cout<<"空间已满!";top++;data[top]=x;}
DataType Pop(){if(top==-1)cout<<"数据已空!";top--;for(int i=0;i<=100;i++)data[i-1]=data[i]; 
return data[0];}
void Show(){if(top==-1)cout<<"数据已空!";for(int i=0;i<=top;i++) cout<<data[i]<<"  ";cout<<endl;}
private:
DataType data[StackSize];
int top;
};
int main()
{SeqStack<int> S;int i;void caidan();
do
{
caidan();cout<<"Please enter your chioce:";cin>>i;
switch(i)
{case 1:cout<<"please eneter the number you want to push:";
int n;cin>>n;S.Push(n);break;
case 2:S.Pop();break;
case 3:S.Show();break;
case 4:break;
default:cout<<"enter error!"<<endl;}}while(i!=4);
return 0;}
void caidan()
{cout<<"1--入队;"<<endl;
 cout<<"2--出队;"<<endl;
 cout<<"3--显示."<<endl;
 cout<<"4--退出;"<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值