
You are required to implement a Priority Queue using A singly linked list in Python.
Each element in the queue consists of:
The queue must always be maintained in sorted order of priority.
| Component | Description |
|---|---|
| Node | Stores data and priority |
| PriorityQueue | Manages the linked list |
| Attribute | Type | Description |
|---|---|---|
| value | any | Data stored in the node |
| priority | int | Priority of the element |
| next | Node | Reference to next node |
| Function | Description |
|---|---|
enqueue(value, priority) |
Insert an element based on priority |
dequeue() |
Remove and return the highest-priority element |
peek() |
Return the highest-priority element without removing |
is_empty() |
Check if the queue is empty |
display() |
Print all elements in priority order |
size() |
Length of all elements in structure |
In many real-world systems, tasks are not processed in the order they arrive. Instead, more important tasks must be handled first.
In this assignment, you will design and implement a Task Scheduling System using a Priority Queue implemented with a Linked List.
You are not allowed to use built-in priority queue libraries (e.g., heapq).
You are asked to build a Task Scheduler that manages tasks based on their priority.
Each task contains:
Tasks are inserted into the system and must be executed in priority order. If two tasks have the same priority, they must be processed in FIFO order.
| Attribute | Type | Description |
|---|---|---|
| task_name | string | Name of the task |
| priority | int | Priority level (lower = higher priority) |
| next | Node | Reference to the next task |
| Function | Description |
|---|---|
add_task(name, priority) |
Insert task in correct priority position |
execute_task() |
Remove and return the highest-priority task |
peek_task() |
View the next task to be executed |
is_empty() |
Check whether the scheduler is empty |
display_tasks() |
Show all pending tasks in order |
1
ADD <task_name> <priority>
Example:
1
2
ADD Backup 3
ADD EmergencyFix 1
Output:
1
2
Task 'Backup' added with priority 3
Task 'EmergencyFix' added with priority 1
1
EXECUTE
Output:
1
Executing task: EmergencyFix (priority 1)
If queue is empty:
1
No tasks to execute.
1
PEEK
Output:
1
Next task to execute: Backup (priority 3)
If queue is empty:
1
No tasks to peek.
1
DISPLAY
Output:
1
2
Current Task Queue:
[EmergencyFix | priority=1] -> [Backup | priority=3] -> None
1
EXIT