Question discussion

A queue is implemented with two stacks: S1 receives every enqueue, and S2 serves every dequeue (the elements are moved from S1 to S2 only w…

2170Medium DSSSB TGT Computer Science 0 replies 1 views
0

A queue is implemented with two stacks: S1 receives every enqueue, and S2 serves every dequeue (the elements are moved from S1 to S2 only when S2 is empty). The operations enqueue(1), enqueue(2), enqueue(3), dequeue, enqueue(4), dequeue are performed in this order. Which element is removed by the second dequeue?

  • A2
  • B1
  • C3
  • D4
Correct answer: A

Explanation

The first dequeue moves 1, 2, 3 into S2 and removes 1; element 4 stays in S1, so the second dequeue pops 2 from S2.

Discussion 0

Nobody has replied yet. Start the discussion!