#C727. Reversible Queue
Reversible Queue
Reversible Queue
You are given a series of commands to operate on a Reversible Queue. The queue supports the following operations:
enqueue x
: Add an integer x to the end of the queue.dequeue
: Remove and output the integer at the front of the queue. If the queue is empty, outputQueue is empty
.reverse
: Reverse the order of the elements in the queue.
Your task is to process these commands in the order given. Note that when the queue is reversed, the enqueue
operation will insert the new element at the front.
Implementation Details: The commands are provided as input, and you should output the results of each dequeue
command on a new line. All I/O must be done using standard input (stdin) and standard output (stdout).
inputFormat
The first line of input contains an integer n representing the number of commands. Each of the following n lines contains a command, which will be in one of the following forms:
enqueue x
dequeue
reverse
outputFormat
For every dequeue
command processed, output the result on a new line. If the queue is empty, output Queue is empty
.
8
enqueue 1
enqueue 2
enqueue 3
reverse
dequeue
enqueue 4
reverse
dequeue
3
1
</p>