/*queue*/
#include<stdio.h>
#include<stdlib.h>
#define queue_size 5
int c,item,f,r,q[10];
void ri()
{
if(r==queue_size-1)
{
printf("queue overflow\n");
return;
}
r=r+1;
q[r]=item;
}
void fd()
{
if(f>r)
{
printf("queue underflow\n");
return;
}
printf("the element deleted is %d",q[(f)++]);
if(f>r)f=0,r=-1;
}
void display()
{
int i;
if(f>r)
{
printf("queue is empty\n");
return;
}
printf("contents of the queue\n");
for(i=f;i<=r;i++)
{
printf("%d\n",q[i]);
}
}
int main()
{
f=0;
r=-1;
for(;;)
{
printf("1:insert 2:delete\n 3:display 4:quit\n");
printf("enter your choice\n");
scanf("%d",&c);
switch(c)
{
case 1:printf("enter the item to be inserted\n");
scanf("%d",&item);
ri();
break;
case 2:fd();
break;
case 3:display(q,f,r);
break;
default:exit(0);
}
}
}
#include<stdio.h>
#include<stdlib.h>
#define queue_size 5
int c,item,f,r,q[10];
void ri()
{
if(r==queue_size-1)
{
printf("queue overflow\n");
return;
}
r=r+1;
q[r]=item;
}
void fd()
{
if(f>r)
{
printf("queue underflow\n");
return;
}
printf("the element deleted is %d",q[(f)++]);
if(f>r)f=0,r=-1;
}
void display()
{
int i;
if(f>r)
{
printf("queue is empty\n");
return;
}
printf("contents of the queue\n");
for(i=f;i<=r;i++)
{
printf("%d\n",q[i]);
}
}
int main()
{
f=0;
r=-1;
for(;;)
{
printf("1:insert 2:delete\n 3:display 4:quit\n");
printf("enter your choice\n");
scanf("%d",&c);
switch(c)
{
case 1:printf("enter the item to be inserted\n");
scanf("%d",&item);
ri();
break;
case 2:fd();
break;
case 3:display(q,f,r);
break;
default:exit(0);
}
}
}