C++ Remove element from the Priority Queue

In C++, the top element can be removed from a priority queue using the pop() method. This method removes the highest priority element from the front of the priority queue. The syntax for pop() method is:

re‮ot ref‬:theitroad.com
priority_queue_name.pop();

Here, priority_queue_name is the name of the priority queue.

For example, let's say we have a priority queue of integers named pq and we want to remove the highest priority element from the queue. We can do this using the pop() method as follows:

#include <iostream>
#include <queue>

using namespace std;

int main() {
    priority_queue<int> pq;

    // Add elements to the priority queue
    pq.push(10);
    pq.push(30);
    pq.push(20);

    // Remove the highest priority element from the front of the priority queue
    pq.pop();

    return 0;
}

In the above code, the pop() method removes the element with the highest priority, which in this case is 30.