Code for simply QUEUE
#include<stdio.h>
#include<conio.h>
void qinsert(int q[],int n,int *f,int *r,int x)
{
if(*r>=(n-1))
{
printf("queue is overflow");
return;
}
*r=*r+1;
q[*r]=x;
if(*f==-1)
*f=0;
}
int qdelete(int q[],int *f,int *r)
{
int a;
if(*f==-1)
return 0;
else
{
if(*f==*r)
{
*f=-1;
*r=-1;
}
else
{
a=q[*f];
*f=*f+1;
}
return(a);
}
}
void display(int q[],int *f,int *r)
{
int i;
if(*f==-1)
printf("queue is empty");
else
{
printf("\nthe queue contains:\n");
for(i=*f;i<=*r;i++)
{
printf("%d ",q[i]);
}
getch();
}
}
void main()
{
int n=5,*f,*r,i,j,k;
intq[5];
*f=-1;
*r=-1;
clrscr();
again:
printf("\n1.insert\n2.delete\n3.display\n4.exit");
printf("enter your choice\n");
scanf("%d",&k);
switch(k)
{
case 1:
printf("enter the value to be inserted\n");
scanf("%d",&j);
qinsert(q,n,f,r,j);
display(q,f,r);
goto again;
case 2:
j=qdelete(q,f,r);
if(j==0)
printf("queue is underflow");
else
{
display(q,f,r);
}
goto again;
case 3:
display(q,f,r);
goto again;
case 4:
goto exit;
}
exit:
}
Comments
Post a Comment