/*
#include <stdio.h>
int main(void)
{
int n, q, r, top=0;
char stack[7]={};
scanf("%d", &n);
q=n;
while (n>26){
q=(n-1)/26;
r=n-(26*q);
if(r==0){
r=26;
}
stack[top]=r+64;
top++;
n=q;
}
stack[top]=q+64;
while(top!=-1){
printf("%c", stack[top]);
top--;
}
return 0;
}
*/
/*
#include <stdio.h>
int stack[5], top=-1;
void push(int data){
stack[++top]=data;
}
int pop(){
if(top!=-1) return stack[top--];
}
void view(){
if(top==-1) {printf("stack is empty!\n"); return ;}
printf("stack >> ");
for(int i=0;i<=top;i++)
printf("%d ",stack[i]);
printf("\n");
}
int main(void)
{
int a, b;
printf("****************stack programm************\n");
while(1){
printf("1. push 2.pop 3. view 4. exit>>");
scanf("%d",&a);
if(a==1){
if(top==4) printf("stack is full!!\n");
else{
printf("push data >>");
scanf("%d",&b);
push(b);
view();
}
}
else if(a==2){
if(top==-1) printf("stack is empty!\n");
else {printf("pop data : %d\n",pop()); view();}
}
else if(a==3) view();
else return 0;
}
}
*/
#include <stdio.h>
#define SIZE 5
int queue[SIZE], rear=0; front=0;
void enqueue(int data)
{
rear=(rear+1)%SIZE;
queue[rear]=data;
}
int dequeue()
{
front=(front+1)%SIZE;
return queue[front];
}
void view()
{
/*
printf("queue>> \n");
for(int i=0;i<SIZE;i++){
if(i==front) printf("%2d X",i);
else printf("%2d %2d",i,queue[i]);
if(i==front) printf(" <- front ");
if(i==rear) printf(" <- rear ");
printf("\n");
}
*/
if(front>rear){
for(int i=front+1; i<SIZE; i++){
printf("%d ", queue[i]);
}
for(int i=0; i<=rear; i++){
printf("%d ", queue[i]);
}
}
else{
for(int i=front+1; i<=rear; i++){
printf("%d ", queue[i]);
}
}
printf("\n");
}
int main(void)
{
int a, b;
printf("QUEUE PROGRAM START\n");
printf("1. enqueue 2. dequeue 3. view 4. exit >> ");
scanf("%d", &a);
while(1)
{
if(a==1){
if((rear+1)%SIZE==front){
printf("FULL\n");
}else{
printf(" INPUT DATA >> ");
scanf("%d", &b);
enqueue(b);
}
}else if(a==2){
if(front==rear){
printf("EMPTY\n");
}else{
printf("DELETED DATA >> %d\n", dequeue());
}
}else if(a==3){}
else{
printf("QUEUE PROGRAM EXIT\n");
return 0;
}
view();
printf("1. enqueue 2. dequeue 3. view 4. exit >> ");
scanf("%d", &a);
}
}