#C8583. Deque Operations Simulation
Deque Operations Simulation
Deque Operations Simulation
You are given a series of commands to manipulate a deque (double‐ended queue). The commands are one of the following:
- PUSH_FRONT x: Insert an integer \(x\) at the front of the deque.
- PUSH_BACK x: Insert an integer \(x\) at the back of the deque.
- POP_FRONT: Remove an element from the front of the deque (if it is non-empty).
- POP_BACK: Remove an element from the back of the deque (if it is non-empty).
You need to execute these commands in the given order and output the final configuration of the deque as a sequence of integers separated by a single space. If the deque is empty, output an empty line.
The input consists of multiple test cases.
inputFormat
The first line contains an integer \(T\) representing the number of test cases. For each test case, the first line contains an integer \(N\) indicating the number of commands. The next \(N\) lines each contain one command from the list above.
All commands are provided through standard input (stdin).
outputFormat
For each test case, output a single line that shows the final state of the deque after processing all commands. The elements should be printed in order from front to back, separated by a single space. If the deque is empty, print an empty line.
The output for all test cases should be printed through standard output (stdout), each on a new line.
## sample5
5
PUSH_BACK 1
PUSH_FRONT 2
PUSH_BACK 3
POP_FRONT
PUSH_FRONT 4
3
PUSH_BACK 1
POP_BACK
POP_FRONT
0
2
POP_BACK
POP_FRONT
7
PUSH_BACK 2
PUSH_FRONT 1
POP_BACK
PUSH_BACK 3
POP_FRONT
PUSH_FRONT 4
PUSH_BACK 5
4 1 3
4 3 5
</p>