QUESTION
(a) Give the representation of a queue as an abstract data type.
(b) What is a priority queue? Give two types of priority queues.
(c) The following program does the following:
1. Create a queue, q, consisting of 1 (front), 2, 3, 4 and 5 (rear).
2. Display the contents of q.
3. Remove an item from q and display the content of q.
#include
#include
#define MAXQUEUE 6
#define TRUE 1
#define FALSE 0
struct queue
{
int items[MAXQUEUE];
int front, rear;
};
void initialize();
int empty();
void insert();
int rem();
void output();
int n;
void main()
{
struct queue q;
int i,E;
initialize(&q);
printf("Enter the number of elements: ");
scanf("%d",&n);
If (n
{
for(i=0;i
{
printf("Enter an element: ");
scanf("%d",&E);
insert(&q,E);
}
}
else
{
printf("Number of elements must be less than MAXQUEUE.\n");
return;
}
printf("\nContent of the Queue from Front to Rear: ");
output(&q);
rem(&q);
printf("\nContent of the Queue from Front to Rear: ");
output(&q);
}
Write the functions initialize, empty, insert and rem in C.