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