Tell me how to implement queue using stack?
Submitted by: AdministratorA 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
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
Top Stack And Queue Questions
☺ | Explain stacks and queues in detail? |
☺ | Tell me how to implement queue using stack? |
☺ | Can you explain queue operation? |
☺ | Do you know what is a circular singly linked list? |
☺ | Tell me what are priority queues? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |