#C306. Linked Queue Operations
Linked Queue Operations
Linked Queue Operations
You are given a linked‐list based queue that supports several operations. Implement a LinkedQueue data structure which supports the following operations:
- ENQUEUE x – insert integer x into the queue.
- DEQUEUE – remove and output the element at the front of the queue. If the queue is empty, output
Empty
. - FRONT – output the front element of the queue without removing it. If the queue is empty, output
Empty
. - ROTATE k – rotate the queue by an integer k positions. Formally, if the queue has n elements then after a rotation with parameter k, the new head becomes the element at position \(k+1\) (using 0-indexing modulo \(n\)).
- REMOVE_DUPLICATES – remove duplicate elements from the queue, keeping only the first occurrence of each.
- PRINT – output the current contents of the queue as a string with values separated by
->
. If the queue is empty, outputEmpty
.
You need to process multiple test cases. In each test case, the operations are executed in order on an initially empty queue. Your program must read from standard input and write to standard output. All formulas in this description adhere to the \( \LaTeX \) format.
inputFormat
The input begins with an integer T representing the number of test cases. For each test case:
- An integer n indicating the number of operations.
- Then n lines follow, each containing one operation command. The possible commands are:
ENQUEUE x
wherex
is an integer.DEQUEUE
FRONT
ROTATE k
wherek
is an integer.REMOVE_DUPLICATES
PRINT
For each operation that requires an output (DEQUEUE
, FRONT
, and PRINT
), print the result on a new line to stdout. If an operation cannot be performed (for example, DEQUEUE
or FRONT
on an empty queue), print Empty
.
outputFormat
Output the result of each operation that produces an output (DEQUEUE
, FRONT
, and PRINT
) in the order they are executed. Each output should be on a separate line.
3
6
ENQUEUE 1
ENQUEUE 2
ENQUEUE 3
PRINT
ROTATE 2
PRINT
8
ENQUEUE 1
ENQUEUE 3
ENQUEUE 1
ENQUEUE 5
ENQUEUE 3
ENQUEUE 7
REMOVE_DUPLICATES
PRINT
8
ENQUEUE 10
ENQUEUE 20
FRONT
DEQUEUE
FRONT
DEQUEUE
DEQUEUE
PRINT
1->2->3
3->1->2
1->3->5->7
10
10
20
20
Empty
Empty
</p>