185. Stack From Two Queues
The mirror of the previous problem: build a working STACK using only queues. You may add at the back, remove from the front, and read the front.
A queue preserves order, so getting the LAST value added to come out first takes real work. There are two standard ways, make adding expensive, or make removing expensive, and either is accepted here.
Constraints - `1 ≤ q ≤ 100000` - `-1000000 ≤ x ≤ 1000000`
Input
The first line contains an integer q, the number of operations.
Each of the next q lines is one operation:
- 1 x, push x
- 2, pop the top value and print it
- 3, print the top value without removing it
Output
Print one line for each 2 and 3 operation, the value, or Empty if the stack holds nothing.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.