Implement Stack/Queue using Queue/Stack
Implement Stack using Queue Use Two Queues Implement a stack API including push(), pop(), top(), empty(). The pop() and top() are the tricky ones to implement. We can use two queues (q1 and q2). push(x): add x to q1; O(1) empty(): check whether q1 is empty; O(1) pop(): move all items from q1 and […]