C++ Get the size of the Priority Queue

To get the size of a priority queue in C++, you can use the size() function. Here's an example:

#include <iostream>
#include <queue>

int main() {
    std::priority_queue<int> pq;
    pq.push(10);
    pq.push(20);
    pq.push(30);
    std::cout << "Size of the priority queue is: " << pq.size() << std::endl;
    return 0;
}
Sourc‮gi.www:e‬iftidea.com

Output:

Size of the priority queue is: 3

In this example, we create a priority queue pq and insert three elements into it using the push() method. Then, we use the size() function to get the number of elements in the priority queue, which is 3.