Page 144 - DCAP407_DATA_STRUCTURE
P. 144
Unit 8: Queues
}
printf("Front inertion not possible\n");
}
void rear_delete(int Q[], int *F, int *R)
{
if(Q_E(*F, *R))
{
printf("Queue underflow\n");
return;
}
printf("The element deleted is %d\n", Q[(*R)--]);
if(*F>*R)
{
*F=0, *R=-1;
}
}
void display(int Q[], int F, int R)
{
int i;
if(Q_E(F, R))
{
printf("Queue is empty\n");
return;
}
printf("Contents of the queue is:\n");
for(i=F;i<=R; i++)
{
printf("%d\n", Q[i]);
}
}
void main()
{
int choice, num, F, R, Q[10];
F=0;
R=-1;
for(;;)
{
printf("1. Insert at front/n");
printf("2. Delete at rear end/n");
printf("3. Display/n");
printf("4. Exit/n");
scanf("%d", &choice);
switch(choice)
{
case 1: printf("Enter the number to be inserted\n");
scanf("%d", &num);
front_insert(num, Q, &F, &R);
break;
case 2: rear_delete(Q, &F, &R);
break;
case 3: display(Q, F, R);
break;
default: exit(0);
LOVELY PROFESSIONAL UNIVERSITY 137