#include <iostream>
using namespace std;
typedef int ElemType ;
#define MAXSIZE 100
#define FALSE 0
#define TRUE 1
typedef struct
{ElemType data[MAXSIZE];
int front,rear;
}SeqQueue;
//初始化
SeqQueue SeqQueueInit()
{SeqQueue Q;
Q.front=Q.rear=-1;
return Q;
}
//入队
SeqQueue SeqQueueIn(SeqQueue Q,ElemType x)
{if((Q.rear+1)%MAXSIZE==Q.front)
{cout<<"队满!/n";
exit(0);
}
Q.rear=(Q.rear+1)%MAXSIZE;
Q.data[Q.rear]=x;
return Q;
}
//出队
SeqQueue SeqQueueOut(SeqQueue Q)
{if(Q.front==Q.rear)
{cout<<"队空!/n";
}
else {Q.front=(Q.front+1)%MAXSIZE;
ElemType x=Q.data[Q.front];
cout<<"出队元素为:"<<x<<endl;
}
return Q;
}
//取队头
ElemType SeqQueueGetHead(SeqQueue Q)
{return (Q.data[Q.front+1]);
}
//判队空
int SeqQueueEmpty (SeqQueue Q)
{if(Q.front==Q.rear)
return TRUE;
else return FALSE;
}
//球队列中的元素个数
int SeqQueueLength(SeqQueue Q)
{return (Q.rear-Q.front+MAXSIZE)%MAXSIZE;
}
//遍历
void SeqQueueTraverse(SeqQueue Q)
{int i;
if(SeqQueueEmpty(Q))
cout<<"队列为空!/n";
else {cout<<"队列中的元素为:/n";
for(i=Q.front+1;i<SeqQueueLength(Q);i++)
cout<<Q.data[i]<<" ";
}
cout<<"/n";
}
int scan()
{int d;
cout<<"请输入所要进行的操作/n";
cout<<"(1 初始化),(2 入队),(3 出队),(4 取队头元素),(5 判队空),(6元素个数),(7 遍历)/n";
cout<<"其他键 推出........./n";
cin>>d;
return (d);
}
int main()
{int can=0;
SeqQueue Q;
ElemType x;
while(!can)
switch(scan())
{case 1:Q=SeqQueueInit();break;
case 2:cout<<"请输出入队元素/n:";
cin>>x;
Q=SeqQueueIn(Q,x);
break;
case 3:Q=SeqQueueOut(Q);
break;
case 4:if(Q.front==Q.rear)
cout<<"队空!"<<endl;
else cout<<"队头元素为:"<<SeqQueueGetHead(Q)<<endl;
break;
case 5:if(SeqQueueEmpty(Q))
cout<<"队空!/n";
else cout<<"队不空!/n";
break;
case 6:cout<<"对中元素个数为:";
cout<<SeqQueueLength(Q)<<endl;;
break;
case 7:SeqQueueTraverse(Q);
break;
default:can=1;
}
return 0;
}