Question: Describe how to implement a queue using two stacks. Show how to implement the dequeue() method. based on the following implementation of the enque() method.
Describe how to implement a queue using two stacks. Show how to implement the dequeue() method. based on the following implementation of the enque() method. What is the worst-case complexity of your dequeue() implementation?
Queue Q1, Q2; // assume you start with two empty queues
void push (Item X) {
Q1.enqueue(X);
}
Item pop( ) { // add comments to explain your idea
}
Complexity of your pop() implementation:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
