Stacks and Queues
You are to come up with combinations of Push/Enque and then
Pop/Dequeue that result in the following outcomes.
You must first use only push or pop on 1, 2, 3, 4, and 5.
Then you must call some combination of Dequeue/Pop 5 times
to get the result.
Assume you have one queue and one stack.
Example: To produce: {1 2 3 4 5} the commands
would be
Enq(1),
Enq(2),
Enq(3),
Enq(4),
Enq(5),
Dequeue()
Dequeue()
Dequeue()
Dequeue()
Dequeue()
Example: To produce: {1 2 3 5 4} the commands
would be
Enq(1),
Enq(2),
Enq(3),
Push(4),
Push(5),
Dequeue()
Dequeue()
Dequeue()
Pop()
Pop()
Problems:
- 1 3 2 4 5
- 5 4 1 2 3
- 1 3 5 4 2
- 1 3 4 5 2