#include< stdio.h>
#include< conio.h>
#define MAX 3
void main()
{
int Q[MAX],f=-1,r=-1,ch,val,i;
char cho='y';
clrscr();
while(cho=='y' || cho=='Y')
{
printf("\n1.Insert \n2.Delete \n3.Show \n4.Exit ");
printf("\n Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(r>=(MAX-1))
{
printf("\n Queue overflow");
}
else
{
printf("\n Enter value:");
scanf("%d",&val);
r++;
Q[r]=val;
if(f==-1)
{
f=f+1;
}
}
break;
case 2:
if(f==-1)
{
printf("\n Queue underflow");
}
else
{
val=Q[f];
printf("\n Deleted element is:%d",val);
if(f==r)
{
f=-1;
r=-1;
}
else
f++;
}
break;
case 3:
if(f==-1)
{
printf("\n Queue empty");
}
else
{
printf("\n content of queue:\n");
for(i=f;i<= r;i++)
{
printf("\t %d",Q[i]);
}
}
break;
case 4:
exit(0);
}
}
getch();
}
OUTPUT
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Queue underflow
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Enter value:11
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Enter value:22
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Enter value:33
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Queue overflow
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:3
content of queue:
11 22 33
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Deleted element is:11
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Deleted element is:22
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Deleted element is:33
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Queue underflow
#include< conio.h>
#define MAX 3
void main()
{
int Q[MAX],f=-1,r=-1,ch,val,i;
char cho='y';
clrscr();
while(cho=='y' || cho=='Y')
{
printf("\n1.Insert \n2.Delete \n3.Show \n4.Exit ");
printf("\n Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(r>=(MAX-1))
{
printf("\n Queue overflow");
}
else
{
printf("\n Enter value:");
scanf("%d",&val);
r++;
Q[r]=val;
if(f==-1)
{
f=f+1;
}
}
break;
case 2:
if(f==-1)
{
printf("\n Queue underflow");
}
else
{
val=Q[f];
printf("\n Deleted element is:%d",val);
if(f==r)
{
f=-1;
r=-1;
}
else
f++;
}
break;
case 3:
if(f==-1)
{
printf("\n Queue empty");
}
else
{
printf("\n content of queue:\n");
for(i=f;i<= r;i++)
{
printf("\t %d",Q[i]);
}
}
break;
case 4:
exit(0);
}
}
getch();
}
OUTPUT
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Queue underflow
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Enter value:11
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Enter value:22
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Enter value:33
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:1
Queue overflow
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:3
content of queue:
11 22 33
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Deleted element is:11
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Deleted element is:22
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Deleted element is:33
1.Insert
2.Delete
3.Show
4.Exit
Enter your choice:2
Queue underflow