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
- A.
It cannot be implemented
- B.
2 stacks
- C.
4 stacks
- 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.