Circular Queue

#include
# define max 4

struct cque
{
int cque[max];
int f,r;
}c;

main()
{
c.f=0;
c.r=-1;
int k=1,ch;
while(k==1)
{printf("\t\t MENU\n"
"\t1.INSERT\n"
"\t2.DELETE\n"
"\t3.DISPLAY\n"
"\t4.EXIT\n"
"\tEnter Your Choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
// display();
break;
case 4:
k=0;
exit(0);
default :
printf("Invalid choice");
}
}
}

insert()
{
int val;
if((c.f == 1 && c.r == max)) //|| c.f = c.r + 1)
{
printf("Over Flow");
}
else if(c.f == 0)
c.f=c.r=1;
else if(c.r == max)
c.r = 1;
else
c.r = c.r + 1;
printf("Enter the value:");
scanf("%d",&val);
c.cque[c.r] = val;
}

delete()
{
if(c.f == 0)
{
printf("Under flow");
}
else
{
printf("deleted Item=%d",c.cque[c.f]);
}
if(c.f == c.r)
c.f = c.r= 0;
else if(c.f = max)
c.f = 1;
else
c.f = c.f + 1;
}

0 comments: