Build a queue with stacks · Compiler

Build a queue with stacks

Implement an initially empty queue using only LIFO stacks for element storage. ENQUEUE x adds x at the back. DEQUEUE removes and reports the oldest value still in the queue. A DEQUEUE on an empty queue reports EMPTY and leaves it empty.

Input
Read q (1 <= q <= 100), followed by q commands, one per line: ENQUEUE x or DEQUEUE. Each x is an integer in [-1000, 1000]. At least one command is DEQUEUE.
Output
Print one line per DEQUEUE, containing the removed integer or EMPTY. Report the results in command order.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…