#include<stdio.h>
#include<conio.h>
#define max 5
int front=-1,rear=-1,cqueue[max];
void incqueue();
void decqueue();
void display();
void main()
{
int i;
clrscr();
printf("program that implements a cqueue.");
printf("\n\n\n\t\t------------OUTPUT------------");
while(1)
{
printf("\n\nenter 1 for inqueue");//taking input from the user
printf("\nenter 2 for dequeue");
printf("\nenter 3 for display");
printf("\npress any other integer key for exit");
printf("\n\nenter the value");
scanf("%d",&i);
if(i==1)
incqueue();
else if(i==2)
decqueue();
else if(i==3)
display();
else
{
printf("exit");
getch();
break;
}
}
}
void incqueue()
{
int d;
if(rear==max-1 && front==0 || rear==front-1)
printf("\n\ncircular queue overflow");
else
{
printf("\nenter the value to be queued");
scanf("%d",&d);
if(rear==-1)
front=0;
if(rear==max-1 )
{
rear=0;
cqueue[rear]=d;
}
else
{
rear++;
cqueue[rear]=d;
}
}
}
void decqueue()
{
int d;
if(front==-1)
printf("\n\ncircular queue underflow");
else
{
if(rear==front)
{
d=cqueue[front];
printf("\n\nthe value that has been dequeued is =%d",d);
rear=-1;
front=-1;
}
else
{
d=cqueue[front];
printf("\n\nthe value that has been dequeued is =%d",d);
if(front==max-1)
front=0;
else
front++;
}
}
}
void display()
{
int j;
if(front==-1)
printf("\n\nthe circular queue is empty");
else
{
if(front>rear)
{
printf("\n\nthe values are=");
for(j=front;j<=max-1;j++)
printf(" %d",cqueue[j]);
for(j=0;j<=rear;j++)
printf(" %d",cqueue[j]);
}
else
{
for(j=front;j<=rear;j++)
printf(" %d",cqueue[j]);
}
}
}