#include
#define maxsize 10
typedef struct
{
int elem[maxsize];
int front,rear;
}queue;
void init_queue(queue *cp)
{
cp->front=0;
cp->rear=0;
}
void en_queue(queue *cp,int x)
{
if((cp->rear+1)%maxsize==cp->front)
printf("The quequ is full!!");
else
{
cp->rear=(cp->rear+1)%maxsize;
cp->elem[cp->rear]=x;
}
}
int dl_queue(queue *cp)
{
if(cp->front==cp->rear)
printf("The queue is empty!!");
else
{
cp->front=(cp->front+1)%maxsize;
return(cp->elem[cp->front]);
}
}
void print(queue *cp)
{
int i;
for(i=cp->front+1;i<=cp->rear;i++)
{
printf("[%d]",cp->elem[i]);
}
}
void main()
{
int x,y;
int select;
queue *cp=NULL;
init_queue(cp);
do
{
printf("\n(1) Input a stack data");
printf("\n(2) Output a stack data");
printf("\n(3) Exit");
printf("\nPlease select one:");
scanf("%d",&select);
switch(select)
{
case 1:printf("\nPlease input the data:");
scanf("%d",&x);
en_queue(cp,x);
printf("\nThe queue is: ");
print(cp);
break;
case 2:y=dl_queue(cp);
printf("\nThe queue is: ");
print(cp);
printf("\nThe putout data is %d",y);
break;
case 3:break;
}
}
while(select<3);
getch();
}