Priority Queue is an extension of the queue with following properties.
1) An element with high priority is dequeued before an element with low priority.
2) If two elements have the same priority, they are served according to their order in the queue.
Below is simple implementation of priority queue.
12 1 14 7 14 12 7 1 ()
Note that the time complexity of delete is O(n) in above code.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Priority Queue | Set 1 (Introduction)
- Binary Heap
- Stack and Queue in Python using queue Module
- Level Order Tree Traversal
- Implementation of Deque using doubly linked list
- Sort a nearly sorted array using STL
- Python Code for time Complexity plot of Heap Sort
- Priority queue of pairs in C++ (Ordered by first)
- Kth smallest element after every insertion
- Microsoft Interview experience | Set 178 (On-Campus Internship for IDC)