Stack And Queue Question:

Tell me how to implement queue using stack?

Tweet Share WhatsApp

Answer:

A queue can be implemented by using 2 stacks:-

1. An element is inserted in the queue by pushing it into stack 1
2. An element is extracted from the queue by popping it from the stack 2
3. If the stack 2 is empty then all elements currently in stack 1 are transferred to stack 2 but in the reverse order
4. If the stack 2 is not empty just pop the value from stack 2.

Download Stack And Queue PDF Read All 6 Stack And Queue Questions
Previous QuestionNext Question
Can you explain queue operation?Explain stacks and queues in detail?