#include<stdio.h>
#include<conio.h>
#include<process.h>
#define max 5
void enqueue();
int dequeue();
void dispqueue();
int cq[max],rear=-1,front=-1,element;
void main()
{
int ch;
clrscr();
do
{
printf("1.INSERTION\n2.DELETION\n3.DISPLAYING\n4.EXIT\n Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: enqueue();
break;
case 2: element=dequeue();
printf("Element is deleted");
break;
case 3: dispqueue();
break;
default : printf("Try again!");
}
}while(ch!=4);
}
void enqueue()
{
if (front==-1 && rear==-1)
{
printf("Enter the element");
scanf("%d",&element);
front=rear=0;
cq[rear]=element;
}
else if ((rear+1)%max==front)
{
printf("CQUEUE IS OVERFLOW");
getch();
}
else
{
printf("enter the element:");
scanf("%d",&element);
rear=(rear+1)%max;
cq[rear]=element;
}
}
int dequeue()
{
if(front==-1&&rear==-1)
{
printf("CQueue is empty!");
getch();
}
else if(front==rear)
{
element=cq[front];
front=rear=-1;
}
else
{
element=cq[front];
front=(front+1)%max;
}
return element;
}
void dispqueue()
{
int i=front;
if (front==-1&&rear==-1)
printf("CQueue is empty");
else
{
while (i!=rear)
{
printf("%d",cq[i]);
i=(i+1)%max;
}
}
getch();
clrscr();
}