![]() |
In C++, a priority queue is a queue in which elements are arranged based on their priority values as each element has a priority value associated with it. In this article, we will learn how to delete an element from a priority queue in C++. For Example, Input: myPriorityQueue = {8, 6, 7, 5, 4, 2, 3} Output: Remove Element from Priority Queue in C++To remove an element from a priority_queue we can use a std::priority_queue::pop() function that directly removes the element with the highest priority (topmost element) from the queue and the element with the next highest priority becomes the top element after deletion. C++ Program to Delete Element from Priority QueueThe below example demonstrates the deletion of an element using pop() in a priority queue. C++
Output
Top element before removal: 50 Top element after removal: 30 Time Complexity: O(log N), where N is the number of elements in the priority queue. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |