Priority Queue Opertions: empty(), pop(), top(), push() : priority_queue « Queue Stack « C++






Priority Queue Opertions: empty(), pop(), top(), push()

   
#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

1.priority_queue of double
2.priority_queue: push, pop, top, empty
3.priority_queue: push and size
4.priority_queue: pop
5.priority_queue: top
6.Define your function to Prioritize a priority_queue
7.Using a Priority Queue
8.A priority_queue: size(), top(), empty(), pop()