About 50 results
Open links in new tab
  1. How can I implement a queue using two stacks? - Stack Overflow

    Suppose we have two stacks and no other temporary variable. Is to possible to "construct" a queue data structure using only the two stacks?

  2. Implement A Queue using Two Stacks Python - Stack Overflow

    Mar 15, 2014 · I've been going over some of the many coding interview questions. I was wondering how you would go about implementing a queue using two stacks in Python? Python is not my strongest …

  3. How to Implement a Queue With Two Stacks - Stack Overflow

    Dec 5, 2015 · Today I had a data structures exam. One of the questions was how to implement queue functions which are enqueue and dequeue given stacks s1 and s2. I have used this method, is this …

  4. java - implement a queue using two stacks - Stack Overflow

    Dec 3, 2013 · More importantly, can you tell us how this is supposed to be implementing a queue in terms of two stacks? If you can tell us how it's supposed to work, then people can start to point out …

  5. Constant amortized complexity for implementing a queue using two …

    May 30, 2014 · This gives you a "overall" cost compared to the worst case O (n) for a single dequeue. In your example, you can show that each element is pushed to a stack two times at max (once for …

  6. What is the point of "Two Stack based Queues"?

    Sep 12, 2023 · When I have to implement a concurrent multi-producer-single-consumer queue in real life, I often implement it using two stacks when an unbounded queue is desired: All producers push …

  7. implement queue using 2 stacks, with constant time complexity

    Nov 11, 2021 · I'm wondering if it is possible to implement a queue using two stacks so that each queue operation takes amortized constant time.

  8. algorithm - Implement Stack using Two Queues - Stack Overflow

    Mar 27, 2009 · A similar question was asked earlier there, but the question here is the reverse of it, using two queues as a stack. The question... Given two queues with their standard operations …

  9. list - Why use two stacks to make a queue? - Stack Overflow

    May 27, 2014 · 3 You can make an immutable queue using two immutable stacks. But, if you just want a mutable queue, using two stacks is a great way to make it slower and more complicated than just …

  10. arrays - Queue using two stacks - Stack Overflow

    0 I think you actually can implement a queue using two adjacent stacks as you described. The problem is that you cannot implement those two adjacent stacks with an array efficiently.