#include<iostream.h>
#include<malloc.h>
#define MaxLen 20
typedef char elemtype;
typedef struct node
{
elemtype data[MaxLen];
int front,rear;
}squeue;
void init(squeue *sq)
{
sq->front=0;
sq->rear=0;
}
squeue *enqueue(squeue *sq,elemtype x)
{
if((sq->rear+1)%MaxLen==sq->front)
{
cout<<"队满"<<endl;
return sq;
}
sq->data[sq->rear]=x;
sq->rear+=1;
return sq;
}
squeue *outqueue(squeue *sq,elemtype *x)
{
if(sq->rear==sq->front)
{
cout<<"空队"<<endl;
return sq;
}
*x=sq->data[sq->front];
sq->front=(sq->front +1)%MaxLen;
return sq;
}
int empty(squeue *sq)
{
if(sq->rear==sq->front)
return 1;
else
return 0;
}
int len(squeue *sq)
{
if(sq->front==sq->rear)
return 0;
else if(sq->rear>sq->front)
return sq->rear-sq->front;
else if(sq->rear<sq->front)
return MaxLen+sq->rear-sq->front;
}