The queue data structure is to be realized by using stack. The number of…

2015

The queue data structure is to be realized by using stack. The number of stacks needed would be

  1. A.

    It cannot be implemented

  2. B.

    2 stacks

  3. C.

    4 stacks

  4. D.

    1 stack

Attempted by 501 students.

Show answer & explanation

Correct answer: B

Implementing a queue using stacks requires two stacks to manage FIFO behavior. One stack handles enqueue operations, while the second reverses elements for dequeue.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro