Data Structures & AlgorithmsEasyWipro · Accenture pattern

What is the minimum number of stacks needed to implement a queue, if no other data structure may be used?

  1. A. 1
  2. B. 4
  3. C. 3
  4. D. 2

Correct answer: D. 2

One stack receives enqueued items; when the other (output) stack is empty, everything is popped across, reversing the order so the oldest item is on top. A single stack can only give LIFO order.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic