#include #include using namespace std; /* * These are simple comparision objects * If something uses a type for comparision * it only looks for the operator binary () * which is basically a operator < definition * * priority queues use a high to low order by default */ template < class T > class Normal { public: bool operator () ( const T & l, const T & r ) const { return ( l < r ); } }; template < class T > class Reverse { public: bool operator () ( const T & l, const T & r ) const { return ( r < l ); } }; int main() { { cout << "normal order heap" << endl; // these all pop the high value //priority_queue q; //priority_queue, less > q; //priority_queue, Normal > q; priority_queue q; q.push( 42 ); q.push( 17 ); q.push( 6 ); q.push( 91 ); cout << q.top() << endl; q.pop(); cout << q.top() << endl; q.pop(); cout << q.top() << endl; q.pop(); } { cout << "reverse order heap" << endl; // these all pop the low value //priority_queue, greater > q; //priority_queue, Reverse > q; priority_queue, Reverse > q; q.push( 42 ); q.push( 17 ); q.push( 6 ); q.push( 91 ); cout << q.top() << endl; q.pop(); cout << q.top() << endl; q.pop(); cout << q.top() << endl; q.pop(); } return 0; }