Possible Duplicate:
Implement Stack using Two Queues
I want the most efficient way in terms of time complexity to implement stack using two queues
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t get why you’d ever need two queues. I’ve seen the answers here and in the dupe thread, and you can do it with just one queue.
From the dupe thread, this has two versions, one that optimizes push, and one that optimizes pop.
Push optimized:
Pop optimized:
Then again, I don’t get why you’d ever want to do this ever. Lambast your professor for making you waste your time with pointless programming questions.