Or login with:
#include <queue> namespace std { template < class T, class Container = vector<T>, class Compare = less<Container::value_type> > class priority_queue; }
// a priority queue of integers sorted using std::less <> (default) priority_queue <int> pqI; // a priority queue of doubles priority_queue <double> pqD; // a priority queue of integers sorted using std::greater <> priority_queue <int, deque <int>, greater <int> > pqIntegers_Inverse;
| Operation | Effect |
|---|---|
| priority_queue< El > pq | Creates an empty priority_queue pq which can hold values of type El |
| priority_queue< El > pq1(pq2) | Creates pq as a copy of pq2, whose component type must be El |
| priority_queue< El > pq1 = pq2 | Copy constructor (alternate usage syntax) |
| Operation | Effect |
|---|---|
| pq1 = pq2 | Assigns pq2 to pq1, and return the common value. The priority_queue on the left of an assignment receives the values and size of the one on the right |
| pq.top() | Returns a reference to the component of pq with the highest priority |
| pq.size() | Returns a value of type size_type giving the number of values currently in pq |
| pq.empty() | Returns true if pq is empty (contains zero values); otherwise returns false |
| pq.push(val) | Adds val to pq, increasing the size of pq by one |
| pq.pop() | Removes the value of pq with the highest priority, decreasing the size of pq by one |
#include <iostream> using std::cout; using std::endl; #include <queue> int main() { std::priority_queue< double > priorities; priorities.push( 4.1 ); priorities.push( 10.7 ); priorities.push( 6.3 ); cout << "Values are: "; while ( !priorities.empty() ) { cout << priorities.top() << ' '; priorities.pop(); } cout << endl; return 0; }
You must login to leave a messge