Define your function to Prioritize a priority_queue
#include <iostream>
#include <string>
#include <queue>
using namespace std;
class Prioritize {
public:
int operator() ( const pair<string, unsigned int>& p1,const pair<string, unsigned int>& p2 ) {
return p1.second < p2.second;
}
};
int main()
{
priority_queue< pair< string, unsigned int >,vector <pair< string, unsigned int > >, Prioritize > pq;
pq.push( pair<string, int>( "A", 2) );
pq.push( pair<string, int>( "B", 10 ) );
pq.push( pair<string, int>( "C", 1 ) );
while ( !pq. empty() ) {
cout << pq.top().first << endl;
pq.pop();
}
return 0;
}
Related examples in the same category