/*#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
*/
/*#include<stdio.h>
#define MAXSIZE 5
int queue[MAXSIZE] = {};
int front = 0, rear = 0;
void push(int k)
{
if(front==MAXSIZE && rear == 0)
{
printf("QUEUE is Full\n");
return;
}
if(front==MAXSIZE&&rear!=0) // front: 5, rear = 1, 2, 3, 4: 1>4, 2>3, 3>2, 4>1
{
for(int i=0; i <front-rear; i++) {
queue[i] = queue[rear+i];
queue[rear+i] = 0;
}
front = front - rear;
rear = 0;
queue[0]=queue[rear];
queue[rear]=0;
queue[front-rear]=queue[front];
for(int i=1; i<front-rear; i++)
{
queue[i]=queue[front-rear+i-1];
printf("%d :> %d (%d)\n", front-rear+i, i, queue[i]);
queue[front-rear+i-1]=0;
}
front = rear;
rear = 0;
*/
/* }
queue[front++] = k;
}
void pop()
{
if(rear == front)
{
printf("QUEUE is Empty\n");
return;
}
printf("Output data is %d\n", queue[rear]);
queue[rear] = 0;
rear++;
}
void view()
{
printf("Q list\n");
for(int i=0; i<MAXSIZE; i++)
{
printf("%d\n", queue[i]);
}
printf("--------------\n");
}
int main()
{
int n, k;
for(;;)
{
printf("1: push, 2:pop, 3:view\n");
scanf("%d", &n);
switch(n)
{
case 1:
printf("input data is: ");
scanf("%d", &k);
push(k);
break;
case 2:
pop();
break;
case 3:
view();
break;
default:
printf("ERROR\n");
break;
}
}
}*/
#include<stdio.h>
#define MAXSIZE 5
int queue[MAXSIZE] = {};
int front = 0, rear = 0;
void push(int k)
{
if(rear-front==1)
{
printf("Circle Shape of QUEUE is Full\n");
return;
}
queue[front] = k;
front++;
front %= MAXSIZE;
}
void pop()
{
if(front%rear==1)
{
printf("Circle Shape of QUEUE is Empty\n");
return;
}
printf("Output data is %d\n", queue[rear]);
queue[rear] = 0;
rear++;
rear%=MAXSIZE;
}
void view()
{
printf("Q list\n");
for(int i=0; i<MAXSIZE; i++)
{
printf("%d\n", queue[i]);
}
printf("--------------\n");
}
int main()
{
int n, k;
for(;;)
{
printf("1: push, 2:pop, 3:view\n");
scanf("%d", &n);
switch(n)
{
case 1:
printf("input data is: ");
scanf("%d", &k);
push(k);
break;
case 2:
pop();
break;
case 3:
view();
break;
default:
printf("ERROR\n");
break;
}
}
}



