#include< stdio.h>
#include< conio.h>
#define MAX 3
#define NULL -1
void main()
{
int Q[MAX],i,j,f=NULL,r=NULL,val,ch,item;
clrscr();
while(1)
{
printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit");
printf("\n Enter Your choice:");
scanf("%d",&val);
switch(val)
{
case 1:
if((f==0 && r==(MAX-1))||(f==r+1))
printf("\nCircular Queue Overflow.");
else
{
if(r==MAX-1)
r=0;
else
r++;
printf("\n Enter value for circular queue:");
scanf("%d",&item);
Q[r]=item;
if(f==NULL)
f=0;
}
break;
case 2:
if(f==NULL)
printf("\n circular queue is empty.");
else
{
printf("\n Deleted element is :%d",Q[f]);
if(f==r)
f=r=NULL;
else if(f==(MAX-1))
f=0;
else
f++;
}
break;
case 3:
if(f==NULL)
printf("\n Circular queue is empty.");
else
{
if(f<=r)
{
for(i=f;i<=r;i++)
printf("\t %d",Q[i]);
}
if(f>r)
{
for(i=f;i<=MAX-1;i++)
printf("\t %d",Q[i]);
for(i=0;i<=r;i++)
printf("\t %d",Q[i]);
}
}
break;
case 4:
exit(0);
}
}
getch();
}
OUTPUT
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:2
circular queue is empty.
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:11
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:22
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:33
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:3
11 22 33
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Circular Queue Overflow.
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:2
Deleted element is :11
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:44
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:3
22 33 44
#include< conio.h>
#define MAX 3
#define NULL -1
void main()
{
int Q[MAX],i,j,f=NULL,r=NULL,val,ch,item;
clrscr();
while(1)
{
printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit");
printf("\n Enter Your choice:");
scanf("%d",&val);
switch(val)
{
case 1:
if((f==0 && r==(MAX-1))||(f==r+1))
printf("\nCircular Queue Overflow.");
else
{
if(r==MAX-1)
r=0;
else
r++;
printf("\n Enter value for circular queue:");
scanf("%d",&item);
Q[r]=item;
if(f==NULL)
f=0;
}
break;
case 2:
if(f==NULL)
printf("\n circular queue is empty.");
else
{
printf("\n Deleted element is :%d",Q[f]);
if(f==r)
f=r=NULL;
else if(f==(MAX-1))
f=0;
else
f++;
}
break;
case 3:
if(f==NULL)
printf("\n Circular queue is empty.");
else
{
if(f<=r)
{
for(i=f;i<=r;i++)
printf("\t %d",Q[i]);
}
if(f>r)
{
for(i=f;i<=MAX-1;i++)
printf("\t %d",Q[i]);
for(i=0;i<=r;i++)
printf("\t %d",Q[i]);
}
}
break;
case 4:
exit(0);
}
}
getch();
}
OUTPUT
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:2
circular queue is empty.
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:11
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:22
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:33
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:3
11 22 33
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Circular Queue Overflow.
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:2
Deleted element is :11
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:1
Enter value for circular queue:44
1.Insert
2.Delete
3.Display
4.Exit
Enter Your choice:3
22 33 44