Using a different comparison function: greater
#include <iostream>
#include <queue>
#include <functional>
using namespace std;
int main()
{
priority_queue<int, vector<int>, greater<int> > q;
q.push(1);
q.push(3);
q.push(4);
while(!q.empty()) {
cout << "Popping ";
cout << q.top() << endl;
q.pop();
}
return 0;
}
Related examples in the same category