Tell me how to implement queue using stack?

Submitted by: Administrator
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.
Submitted by: Administrator

Read Online Stack And Queue Job Interview Questions And Answers