A priority queue is a dynamically resizing container adopter in the C++ Standard Library. Elements in a priority queue are arranged in non-decreasing order such that the first element is always the greatest element in the queue. The priority_queue::size()
is a method available in the STL which returns the number of elements in a priority queue.
Syntax:
priorityq_name.size();
Parameters: The priority_queue::size()
does not accept any parameters
Return value: Number of elements in the priority queue.
Example of priority_queue::size() method
#include <iostream>> #include <queue> using namespace std; int main () { priority_queue<int> q1; q1.push(10); q1.push(20); q1.push(40); q1.push(30); q1.push(50); cout<<"Size of container is: "<<q1.size(); return 0; }
Output:
Size of container is: 5