How to implement "Queue" functionality by using "2 Stacks"?
Submitted by: Administrator1. Take 2 empty stacks.
2. Fill the 1st stack with some items (eg: input 100, 101, 102, 103)
3. Now read the items from 1st stack in LIFO order and write to 2nd stack.
(By this the 2nd stack will get the items in the order .. 103, 102, 101, 100)
4. Now read the items from 2nd stack in LIFO order i.e. the output will be
100, 101, 102, 103.
(this is the queue order FIFO with respect to the actual items entered in 1st
stack.)
Submitted by: Administrator
2. Fill the 1st stack with some items (eg: input 100, 101, 102, 103)
3. Now read the items from 1st stack in LIFO order and write to 2nd stack.
(By this the 2nd stack will get the items in the order .. 103, 102, 101, 100)
4. Now read the items from 2nd stack in LIFO order i.e. the output will be
100, 101, 102, 103.
(this is the queue order FIFO with respect to the actual items entered in 1st
stack.)
Submitted by: Administrator
Read Online Programming Concepts Job Interview Questions And Answers
Top Programming Concepts Questions
☺ | Explain how Search engines work? |
☺ | Explain what is port? what is HTTP port, FTP port, Telnet port and others? |
☺ | What is the client business process in electronic industry (in mySAP CRM)? |
☺ | Explain how to get 1,4,7,10.....rows from a table? |
☺ | Write an O(log2(N)) algorithm to find X^N? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |