The seven elements A, B, C, D, E, F and G are pushed onto a stack in reverse…
2017
The seven elements A, B, C, D, E, F and G are pushed onto a stack in reverse order, i.e., starting from G. The stack is popped five times and each element is inserted into a queue. Two elements are deleted from the queue and pushed back onto the stack. Now, one element is popped from the stack. The popped item is ________.
- A.
A
- B.
B
- C.
F
- D.
G
Attempted by 574 students.
Show answer & explanation
Correct answer: B
Solution:
Initially push elements starting from G: push G, F, E, D, C, B, A. The stack (top to bottom) is A, B, C, D, E, F, G.
Pop five times and enqueue each popped element: pop A, B, C, D, E and enqueue them in that order. The queue (front to rear) becomes A, B, C, D, E. Remaining stack (top to bottom) is F, G.
Dequeue two elements and push them onto the stack: dequeue A then B, pushing A then B results in stack (top to bottom) B, A, F, G.
Pop one element from the stack: the top element B is popped.
Answer: B