In a queue following operations were performed:
enqueue(8), enqueue(4), dequeue(), enqueue(7), enqueue(15), dequeue(), enqueue(18), dequeue(), enqueue(8), enqueue(4).
What will be the order of the elements in the queue starting from rear to front?
(A) 15
(B) 4
(C) 18
(D) 8
In a queue following operations were performed:
enqueue(8), enqueue(4), dequeue(), enqueue(7), enqueue(15), dequeue(), enqueue(18), dequeue(), enqueue(8), enqueue(4).
What will be the order of the elements in the queue starting from rear to front?
(A) 15
(B) 4
(C) 18
(D) 8
Solution
A queue is FIFO: elements are added at the rear and removed from the front.
| Operation | Queue (front to rear) |
|---|---|
| enqueue(8) | 8 |
| enqueue(4) | 8, 4 |
| dequeue() removes 8 | 4 |
| enqueue(7) | 4, 7 |
| enqueue(15) | 4, 7, 15 |
| dequeue() removes 4 | 7, 15 |
| enqueue(18) | 7, 15, 18 |
| dequeue() removes 7 | 15, 18 |
| enqueue(8) | 15, 18, 8 |
| enqueue(4) | 15, 18, 8, 4 |
The final queue from front to rear is 15, 18, 8, 4, so from rear to front the order is:
(B) 4
(D) 8
(C) 18
(A) 15
Option 1: lists the elements in the front-to-back order of insertion of the labels, not the queue's rear-to-front order.
Option 4: places 18 at the rear, but 18 was enqueued before the last 8 and 4.
Related questions:
2026: 19 May Shift 1
2025: 16 May Shift 1