490 Programming and Data Structures
In Fig. 14.15 (a) the above queue is empty, hence the value of rear = -1 and front = -1. The above
queue is called an empty queue. The status of the queue initially always remains empty
rear = 0
front = 0
(b)
In Fig. 14.15(b), the queue holds one element. The value of rear=0 and front=0. Both front and rear
end are on same element because the queue contains only one element. The next element appended
will be stored followed by 5. Just then, the front will remain at 5 but rear will be shifted on the new
element. The value of front is changed only once while inserting first element in the queue. Later for
every insertion of element, the front remains the same.
5 3
front = 0
rear = 1
0
1 2 3
4
5
(c)
As per Fig. 14.15(c), an element is inserted from the rear side and it is stored behind five. Whenever
we insert an element in the queue the value of rear is incremented, that is, the rear end is shifted
towards the right side. At this step the value of front =0 and rear=l.
5 3 2
front = 0
rear = 1
0
1 2 3 4 5
(d)
Fig. 14.15(d), the value of rear is 2.
front = 1
rear = 2
0 1 2 3 4 5
(e)
Fig. 14.15 Various positions of queue
In Fig. 14.15 (e), one element is deleted from the queue. Now the front is shifted towards bottom.
Thus, the front will be on element 3 now. The value of front will be increased when an element is
removed. The value of front=l and rear = 2. The programs on the above discussion are explained in
queue implementation.