#include
#define max 5
int front=-1,rear=-1;
int cq[max];
void main()
{
int rpt=1;
int ch;
clrscr();
while(rpt)
{
printf("1.cqinsert\n");
printf("2.cqdelete\n");
printf("3.cqdisplay\n");
printf("4.exit\n");
printf("enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:cqinsert();
break;
case 2:cqdelete();
break;
case 3:cqdisplay();
break;
case 4:return;
}
printf("Do you want to continue press 1 for yes and 0 for no\n");
scanf("%d",&rpt);
}
}
cqinsert()
{
int num;
if(front==(rear+1)%max)
{
printf("queue is full\n");
return;
}
else
{
printf("enter the element\n");
scanf("%d",&num);
rear=rear+1%max;
cq[rear]=num;
if(front==-1)
front=0;
}
}
cqdelete()
{
int num;
if(front==-1)
{
printf("queue is empty\n");
return;
}
else
{
num=cq[front];
printf("Deleted number is %d",num);
if(front==rear)
front=rear=-1;
else
front=(front+1)%max;
}
}
cqdisplay()
{
int i;
if(front==-1)
{
printf("queue is empty\n");
return;
}
else if(front
for(i=front;i<=rear;i++)
printf("%d\n",cq[i]);
}
else
{
for(i=front;i
for(i=0;i<=rear;i++)
printf("%d\n",cq[i]);
}
}
No comments:
Post a Comment