Implement a queue Q using two stacks S1 and S2 so that the operations ENQUEUE(Q, X) and DEQUEUE(Q, Y), where Q is allegedly a queue and X is the element to be added to Q and Y is the element removed from Q, are handled by the stacks that function as a queue. Assume that only stacks are accessible to the ADT operations of PUSH, POP, and EMPTYSTACK. Show how your method operates on the list "a, b, c," which the stacks "S1" and "S2" will use as a queue.
Implement a queue Q using two stacks S1 and S2 so that the operations ENQUEUE(Q, X) and DEQUEUE(Q, Y), where Q is allegedly a queue and X is the element to be added to Q and Y is the element removed from Q, are handled by the stacks that function as a queue. Assume that only stacks are accessible to the ADT operations of PUSH, POP, and EMPTYSTACK. Show how your method operates on the list "a, b, c," which the stacks "S1" and "S2" will use as a queue.
Question
Implement a queue Q using two stacks S1 and S2 so that the operations ENQUEUE(Q, X) and DEQUEUE(Q, Y), where Q is allegedly a queue and X is the element to be added to Q and Y is the element removed from Q, are handled by the stacks that function as a queue. Assume that only stacks are accessible to the ADT operations of PUSH, POP, and EMPTYSTACK.
Show how your method operates on the list "a, b, c," which the stacks "S1" and "S2" will use as a queue.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)