#include <stdlib.h>
#define MAXSIZE 10
typedef struct CQNode
{
int data[MAXSIZE];
int front;
int end;
}CQNode,*CQList;
void InitCQL(CQList CQ)
{
if(CQ==NULL)
CQ=(CQList)malloc(sizeof(CQNode));
CQ->front=0;
CQ->end=0;
}
void InsertCQL(CQList CQ,int value)
{
if((CQ->end-CQ->front+MAXSIZE+1)%(MAXSIZE)==0)
{
printf("Queue is full");
printf("%d is not insert/n",value);
return ;
}
else
{
CQ->data[CQ->end]=value;
CQ->end++;
CQ->end=CQ->end%MAXSIZE;
}
}
int DeleteCQL(CQList CQ)
{
int res;
if(CQ->end==CQ->front)
{
printf("Queue is empty/n");
return -1;
}
else
{
res=CQ->data[CQ->front];
CQ->front++;
CQ->front=CQ->front%MAXSIZE;
}
return res;
}
void Print(CQList CQ)
{
int i;
i=CQ->front;
while(i!=CQ->end)
{
printf("%d,",CQ->data[i]);
i++;
if(i==MAXSIZE)
i=0;
}
printf("/n");
}
int main()
{
int i,val;
CQList cl;
cl=(CQList)malloc(sizeof(CQNode));
InitCQL(cl);
for(i=1;i<12;i++)
{
InsertCQL(cl,i*3+3);
}
Print(cl);
getch();
for(i=1;i<7;i++)
{
val=DeleteCQL(cl);
if(val!=-1)
printf("%d is deleted/n",val);
}
getch();
for(i=4;i<12;i++)
{
InsertCQL(cl,i*6);
}
Print(cl);
getch();
return 0;
}