We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Queue using Two Stacks
Queue using Two Stacks
Sort by
recency
|
493 Discussions
|
Please Login in order to post a comment
Here's my code in C++
Approach : Here I'm using two stacks s1(as an supplementary stack) and s2 (acts as the main queue) , the top element of s2 will act as the Front element of the queue. *I've written comments to help you understand the execution of queries, hope it help ;) *
First include the Stack Library using :
#include <stack>
1) This problem explains what a queue is and how it operates. Then it states you'll implement a queue by building two stacks. No explanation whatsover regarding what stacks are or what methods they implment. Nevermind that the code has no means to ensure your implementation utilizes stacks.
2) The explanation of what a queue is says it implements enqueue and dequeue then asks you to do a peek.
C# Solution :
Python 3 solution