
Problems on Queues
1) Given a queue of size 10 find out how many elements are there in the queue when
the indices front and rear have the following values?
For your understanding you can draw a queue of size and mark the front and rear
indices to verify that the following solutions are correct.
front = 0 and rear =2
This shows that first 3 slots are occupied.
front = 0 and rear =9
This shows all the 10 slots are occupied.
front =4 and rear =4
Since front=rear and not equal to -1, it means that there is only one slot is occupied.
front = 6 and rear = 5
Since front =rear + 1, it means that the queue is full, with all slots occupied.
front = 6 and rear = 4
Now front =rear + 1 means that the queue is full, but here front = rear+ 2, it
means that still 1 slot is free. (There are 9 elements in the queue).
2) Consider a queue of size 5 . Using the concept of circular array implementation
show the contents of the queue after the following operations are carried out
Enqueue 6
Enqueue 7
Enqueue 2
X = dequeue
Enqueue 9
Y = dequeue
Enqueue 5
Enqueue 4
Enqueue 6
Z = dequeue
Enqueue Y
X = dequeue
Enqueue Z
Y = dequeue