#define size 5
void
in(void),del(void),dis(void);
int
que[size],num,n=0,front=0,rear=-1;
char con;
void main()
{
printf("\n\n\tMain
Menu\n1.Insert\n2.Delete\n3.Display\n4.Exit\nEnter choice:");
scanf("%d",&num);
clrscr();
switch(num)
{
case 1:
in();
break;
case 2:
del();
break;
case 3:
dis();
break;
case 4:
exit();
default:
puts("\nWRONG
INPUT!!!");
}
main();
}
void in(void)
{
do
{
if(n==size)
{
clrscr();
puts("\nQueue is
full!!!");
break;
}
printf("\nEnter number:");
scanf("%d",&num);
rear=(rear+1)%size;
que[rear]=num;
n++;
printf("Continue?
[y/n]:");
con=getche();
}while(con=='y'||con=='Y');
}
void del(void)
{
do
{
if(n==0)
{
clrscr();
puts("Queue is
empty!!!");
break;
}
front=(front+1)%size;
n--;
printf("Continue?
[y/n]:");
con=getche();
}while(con=='y'||con=='Y');
}
void dis(void)
{
int i;
clrscr();
if(n==0)
{
puts("Queue is empty!!!");
return;
}
printf("The queue is: ");
for(i=front;i!=rear;i=(i+1)%size)
printf("%d ",que[i]);
printf("%d",que[i]);
}
No comments:
Post a Comment