Build a stack with queues · Compiler

Build a stack with queues

Implement an initially empty stack using only FIFO queues for element storage. PUSH x adds x to the top. POP removes and reports the most recently pushed value still in the stack. A POP on an empty stack reports EMPTY and leaves it empty.

Input
Read q (1 <= q <= 100), followed by q commands, one per line: PUSH x or POP. Each x is an integer in [-1000, 1000]. At least one command is POP.
Output
Print one line per POP, 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…