Given Nodes with their priority, implement a priority queue using doubly linked list.
Prerequisite : Priority Queue
Operations on Priority Queue :
- push(): This function is used to insert a new data into the queue.
- pop(): This function removes the element with the lowest priority value form the queue.
- peek() / top(): This function is used to get the lowest priority element in the queue without removing it from the queue.
1. Create a doubly linked list having fields info(hold the information of the Node), priority(hold the priority of the Node), prev(point to previous Node), next(point to next Node).
2. Insert the element and priority in the Node.
3. Arrange the Nodes in the increasing order of the priority.
Below is the implementation of above steps :
Related Article :
Priority Queue using Singly Linked List
Time Complexities and Comparison with Binary Heap:
peek() push() pop() ----------------------------------------- Linked List | O(1) O(n) O(1) | Binary Heap | O(1) O(Log n) O(Log n)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Priority Queue using Linked List
- Python | Queue using Doubly Linked List
- Difference between Singly linked list and Doubly linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Construct a Doubly linked linked list from 2D Matrix
- Priority Queue using Queue and Heapdict module in Python
- QuickSort on Doubly Linked List
- Doubly Linked List Tutorial
- Reverse a Doubly Linked List | Set-2
- Reverse a Doubly Linked List
- Doubly Circular Linked List | Set 2 (Deletion)
- Rotate Doubly linked list by N nodes
- Find pairs with given sum in doubly linked list
- Sort the biotonic doubly linked list | Set-2
- Delete a node in a Doubly Linked List
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Implementation of Deque using doubly linked list
- Insertion Sort for Doubly Linked List
- Merge Sort for Doubly Linked List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.