#include <stdio.h>
#define SIZE 5
int Q[SIZE] = {};
int front, rear;
int init()
{
rear = 0;
front = 0;
for(int i= 0;i<SIZE;i++)
{
Q[i]=0;
}
}
int isFull()
{
if((rear+1)%SIZE == front)
{
return 1;
}
else
{
return 0;
}
}
int isEmpty()
{
if(front == rear)
{
return 1;
}
else
{
return 0;
}
}
void enQueue(int data)
{
if(!isFull())
{
rear = (rear + 1) % SIZE;
Q[rear]=data;
}
else
{
printf("가득 참\n");
}
return ;
}
int deQueue()
{
int tmp;
if(!isEmpty())
{
front = (front + 1)% SIZE;
tmp=Q[front];
Q[front]=0;
return tmp;
}
else
{
printf("비어 있음\n");
return 0;
}
}
void view()
{
for(int i = 0; i < SIZE; i++)
{
printf("%2d ",i);
}
printf("\n");
for(int i = 0; i < SIZE; i++)
{
printf("%2d ",Q[i]);
}
printf("\n");
/*
if(front > rear)
{
for(int i = front+1; i <= front+rear+2; i++)
{
printf("%2d ",i%SIZE);
}
printf("\n");
for(int i = front+1; i <= front+rear+2; i++)
{
printf("%2d ",Q[i%SIZE]);
}
printf("\n");
}
else
{
for(int i = front+1; i <= rear; i++)
{
printf("%2d ",i);
}
printf("\n");
for(int i = front+1; i <= rear; i++)
{
printf("%2d ",Q[i]);
}
printf("\n");
}
*/
}
int main()
{
int n, k;
init();
while(1)
{
printf("1.enQueue 2.deQueue 3.view 4.init \n");
scanf("%d",&n);
if(n == 1)
{
printf("입력할 숫자를 쓰세요\n");
scanf("%d",&k);
enQueue(k);
}
else if(n == 2)
{
printf("result : %d\n",deQueue());
}
else if(n == 3)
{
view();
}
else
{
init();
}
}
return 0;
}