#C14069. Task Queue Manager: Regular vs Priority Queue
Task Queue Manager: Regular vs Priority Queue
Task Queue Manager: Regular vs Priority Queue
Your task is to implement a task manager that supports two types of queues:
- Regular Queue: Implements the FIFO (first-in-first-out) principle.
- Priority Queue: Implements the minimum-heap principle. In this problem, a task with a lower priority value will be considered as having a higher priority.
Each queue supports the following operations:
ADD description priority
: Add a task with a string description and an integer priority.REMOVE
: Remove the next task from the queue and print its description. If the queue is empty, printNULL
.UPDATE index new_description new_priority
: Update the task at the specified index (0-indexed) with a new description and new priority value. (It is guaranteed that an update operation will always use index 0 when the queue has only one element.)NEXT
: Print the description of the task that is next in line (i.e. the front element for the regular queue or the highest priority task for the priority queue). If the queue is empty, printNULL
.
The input consists of two parts. The first part represents operations on the Regular Queue, and the second part represents operations on the Priority Queue. You must process all operations from stdin
and print the outputs in the order they occur to stdout
.
Note: For the priority queue, use the ordering based on the following \( \texttt{Task} \) comparison: one task is considered less than another if its priority is lower. That is, tasks with lower integer priority values have higher priority.
inputFormat
The input is read from standard input and has the following format:
<N> Operation_1 Operation_2 ... Operation_N <M> Operation_1 Operation_2 ... Operation_M
Here, N
is the number of operations to be performed on the Regular Queue, and M
is the number of operations for the Priority Queue. Each operation is one of the following commands:
ADD description priority
REMOVE
UPDATE index new_description new_priority
NEXT
outputFormat
The output is printed to standard output. For each operation that requires an output (REMOVE
and NEXT
), print the resulting task's description or NULL
if the queue is empty. The results of operations for the Regular Queue appear first, followed by the results for the Priority Queue. Each output should be printed on its own line.
5
ADD taskA 5
NEXT
REMOVE
NEXT
REMOVE
5
ADD taskB 10
ADD taskC 1
NEXT
REMOVE
NEXT
taskA
taskA
NULL
NULL
taskC
taskC
taskB
</p>