Priority Queue Using Linked List

Start Timer

0:00:00

Upvote
7
Downvote
Save question
Mark as completed
View comments (1)

Priority queues are an abstract data structure responsible for allowing enqueuing items with an attached priority. While typically implemented with a heap, implement a priority queue using a linked list.

The Priority Queue implementation should support the following operations:

  • insert(element, priority): This operation should be able to insert an element into the Priority Queue, along with its corresponding priority.
  • delete(): This operation should remove and return the element with the highest priority. If multiple elements share the same highest priority, the element first enqueued should be returned. In the case that the queue is empty, return None.
  • peek(): This operation should return the element with the highest priority without removing it from the Priority Queue. Again, in the case of equal highest priorities, the element first enqueued should be returned. In the case that the queue is empty, return None.

Note: Smaller priority values imply that they have higher priority.

Input

queue.insert(2, 1)
queue.insert(3, 3)

Output:

[2,3]
.
.
.
.
.


Comments

Loading comments