#include<iostream>
using namespace std;
#define QueueSize 50
typedef char ElemType;
typedef struct
{
ElemType data[QueueSize];
int front,rear;
}SqQueue;
void InitQueue(SqQueue *&q)//初始化队列
{
q=new SqQueue;
q->front=q->rear=0;
}
void EnQueue(SqQueue *&q,ElemType x)//入队列
{
if((q->rear+1)%QueueSize==q->front)
{
cout<<"上溢,无法入队"<<endl;
}
else
{
q->rear=(q->rear+1)%QueueSize;
q->data[q->rear]=x;
cout<<"入对成功"<<endl;
}
}
void DeQueue(SqQueue *&q)//出队
{
if(q->rear==q->front)
{
cout<<"下溢,无法出队"<<endl;
}
else
{
q->front=(q->front+1)%QueueSize;//出队,对头指针+1
cout<<"出队元素为:"<<q->data[q->front]<<endl;//取出队头元素
}
}
void GetQueue(SqQueue *q)//获取队头元素
{
if(q->rear ==q->front)
{
cout<<"空队列,无元素"<<endl;//空队列
}
else
{
q->front =(q->front +1)%QueueSize;
cout<<"头元素为:"<<q->data[q->front]<<endl;
}
}
void QueueEmpty(SqQueue *q)//判断队列是否为空
{
if(q->front==q->rear)
{
cout<<"队列为空"<<endl;
}
else
{
cout<<"队列不为空"<<endl;
}
}