#include<bits/stdc++.h>
using namespace std;
#define MAXN 101
#define QelemType int
#define Status int
typedef struct{
QelemType *base;
int front;
int rear;
}SqQueue;
Status InitQueue(SqQueue &q)
{
q.base = new QelemType[MAXN];
if(!q.base)
{
cout<<"初始化错误"<<endl;
return 0;
}
q.front=q.rear=0;
}
Status Queuelength(SqQueue q)
{
return (q.rear-q.front+MAXN)%MAXN;
}
Status EnQueue(SqQueue &q,QelemType e)
{
if((q.rear+1)%MAXN==q.front)
{
cout<<"队列已满"<<endl;
return 0;
}
q.base[q.rear] = e;
q.rear = (q.rear+1)%MAXN;
cout<<"入队完成"<<endl;
return 1;
}
Status OutQueue(SqQueue &q)
{
if(q.front==q.rear)
{
cout<<"队列为空"<<endl;
return 0;
}
int e;
e = q.base[q.front];
q.front = (q.front+1)%MAXN;
cout<<e;
cout<<"出队完成"<<endl;
return 1;
}
void ReadQueue(SqQueue q)
{
if(q.front==q.rear)
{
cout<<"队列为空"<<endl;
return ;
}
for(int i=q.front;;i=(i+1)%MAXN)
{
if(i==q.rear)
break;
cout<<q.base[i]<<" ";
}
cout<<endl;
}
void menu()
{
cout<<"1、初始化"<<endl<<"2、入队"<<endl<<"3、出队"<<endl<<"4、全队阅览"<<endl<<"5、求队列长度"<<endl<<"6、退出程序"<<endl;
}
int main()
{
SqQueue que;
menu();
while(1)
{
int n;
cin>>n;
switch(n)
{
case 1:
InitQueue(que);
break;
case 2:
int x;
cin>>x;
EnQueue(que,x);
break;
case 3:
OutQueue(que);
break;
case 4:
ReadQueue(que);
break;
case 5:
cout<<Queuelength(que)<<endl;
break;
case 6:
exit(0);
}
}
return 0;
}