/* Program to insert and delete items in circular queue */
#include<stdio.h>
#include<conio.h>
void main()
{
int F=0,R=0,N=3,X,Q[10],choice;
clrscr();
start:
printf("Enter your choice 1.Insert 2.Delete 3.Exit:");
scanf("%d",&choice);
if(choice==1)
{
if((R+1==F)||(F==1 && R==N))
{
printf("Queue Overflow.\n");
}
else
{
printf("Enter the item to be inserted:");
scanf("%d",&X);
if(R==N)
{
R=1;
}
else
{
R++;
}
Q[R]=X;
if(F==0)
{
F=1;
}
}
goto start;
}
else if(choice==2)
{
if(F==0)
{
printf("Queue Underflow.\n");
}
else
{
X=Q[F];
printf("The deleted item is %d.\n",X);
if(F==R)
{
F=R=0;
}
else if(F==N)
{
F=1;
}
else
{
F++;
}
}
goto start;
}
else
{
printf("The program for insertion and deletion in circular queue ends here.");
}
getch();
}
/* Output
Enter your choice 1.Insert 2.Delete 3.Exit:2
Queue Underflow.
Enter your choice 1.Insert 2.Delete 3.Exit:1
Enter the item to be inserted:5
Enter your choice 1.Insert 2.Delete 3.Exit:1
Enter the item to be inserted:6
Enter your choice 1.Insert 2.Delete 3.Exit:1
Enter the item to be inserted:7
Enter your choice 1.Insert 2.Delete 3.Exit:2
The deleted item is 5.
Enter your choice 1.Insert 2.Delete 3.Exit:2
The deleted item is 6.
Enter your choice 1.Insert 2.Delete 3.Exit:1
Enter the item to be inserted:3
Enter your choice 1.Insert 2.Delete 3.Exit:1
Enter the item to be inserted:5
Enter your choice 1.Insert 2.Delete 3.Exit:1
Queue Overflow.
Enter your choice 1.Insert 2.Delete 3.Exit:3
The program for insertion and deletion in circular queue ends here.
*/
Share:
These icons link to social bookmarking sites where readers can share and discover new web pages.
