Stack And Queue Question:
Download Questions PDF

Tell me how to implement queue using stack?

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 Interview Questions And Answers PDF

Previous QuestionNext Question
Can you explain queue operation?Explain stacks and queues in detail?