#include <queue> bool empty() const;
The empty() function returns true if the priority queue has no elements, false otherwise.
For example, the following code uses empty() as the stopping condition on a (C/C++ Keywords) while loop to clear a priority queue and display its contents in reverse order:
vector<int> v; for( int i = 0; i < 5; i++ ) { v.push_back(i); } while( !v.empty() ) { cout << v.back() << endl; v.pop_back(); }
#include <queue> void pop();
The function pop() removes the top element of the priority queue and discards it.
#include <queue> priority_queue( const Compare& cmp = Compare(), const Container& c = Container() ); priority_queue( input_iterator start, input_iterator end, const Compare& comp = Compare(), const Container& c = Container() );
Priority queues can be constructed with an optional compare function cmp and an optional container c. If start and end are specified, the priority queue will be constructed with the elements between start and end.
#include <queue> void push( const TYPE& val );
The function push() adds val to the end of the current priority queue.
For example, the following code uses the push() function to add ten integers to the end of a queue:
queue<int> q; for( int i=0; i < 10; i++ ) q.push(i);
#include <queue> size_type size() const;
The size() function returns the number of elements in the current priority queue.
#include <queue> TYPE& top();
The function top() returns a reference to the top element of the priority queue.
For example, the following code removes all of the elements from a stack and uses top() to display them:
while( !s.empty() ) { cout << s.top() << " "; s.pop(); }