#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 5
typedef int ElemType;
typedef struct LinkQueue
{
ElemType *base;
int front;
int rear;
}LinkQueue;
void InitQueue(LinkQueue *q)
{
q->base=(ElemType*)malloc(MAXSIZE*sizeof(ElemType));
if(q==NULL)
{
exit(0);
}
q->front=q->rear=0;
}
void InsertQueue(LinkQueue *q,ElemType e)
{
if((q->rear+1)%MAXSIZE==q->front)
{
return;
}
q->base[q->rear]=e;
q->rear=(q->rear+1)%MAXSIZE;
}
void DeleteQueue(LinkQueue *q,ElemType *e)
{
if(q->rear==q->front)
{
return;
}
*e=q->base[q->front];
q->front=(q->front+1)%MAXSIZE;
}
int main()
{
LinkQueue q;
InitQueue(&q);
ElemType e1;
for(int i=0;i<4;i++)
{
InsertQueue(&q,i);
}
for(int i=0;i<4;i++)
{
DeleteQueue(&q,&e1);
printf("%d ",e1);
}
return 0;
}