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
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
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, data-structures-and-algorithms and related others by exploring similar questions and additional content below.