#include <stdio.h>
#include <stdlib.h>
#define MAX 5
char a[MAX];
int front = 0, rear = -1, count = 0;
void insert()
{
char item;
if(count==MAX)
{
printf("\n\t\tCircular Queue Overflow");
return;
}
else
{
printf("\n\t Enter the Element: ");
scanf("%s",&item);
rear=(rear+1)%MAX;
a[rear] = item;
count = count + 1;
}
}
void del()
{
char item;
if(count == 0)
{
printf("\n\t\tCircular Queue Underflow");
return;
}
else
{
item = a[front];
front = (front+1)%MAX;
count = count - 1;
printf("\n\tDeleted Item = %c",item);
}
}
void display()
{
int i,j=front;
if(count == 0)
{
printf("\n\t\tCircular Queue is Empty");
return;
}
else
{
printf("\n\tFront = %d Rear = %d Count = %d\n",front,rear,count);
printf("\n\tCircular Queue Elements are: \n\n");
for(i=1;i<=count;i++)
{
printf("\t%d",j);
j = (j+1)%MAX;
}
printf("\n");
j = front;
for(i=1;i<=count;i++)
{
printf("\t%c",a[j]);
j = (j+1)%MAX;
}
}
}
int main()
{
int ch;
do
{
printf("\n\n\t\tCircular Queue\n\n");
printf("\t<1> Insert\n");
printf("\t<2> Delete\n");
printf("\t<3> Display\n");
printf("\t<4> Exit\n\n");
printf("\t Enter Your Choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
display();
break;
case 2: del();
display();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\n\tInvalid Choice") ;
break;
}
} while(ch!=5);
return 0;