template <class T, class Container = vector<T>, class Compare = less<typename Container::value_type> > class priority_queue;
例子
#include #include #include #include #include
, greater
> q; for (int i = 0; i < 10; i++) { q.push(rand()%20); } while (!q.empty()) { cout << q.top() << " "; q.pop(); } cout <
b.y;}/** 运算符重载 **/void overloadOperator() { cout << "=========overload Operator< =========" << endl; cout << "a.x < b.x; a.y > b.y" << endl; priority_queue q; for (int i = 0; i < 10; i++) { q.push( Node( rand()%20, rand()%20 ) ); } while (!q.empty()) { cout << q.top().x << "," << q.top().y << endl; q.pop(); } cout << endl; }//=========================/** 自构建比较函数 **/struct cmp2{ bool operator()(int a, int b) { return a < b; }};void designCmp() { cout << "=========designCmp========" << endl; cout << "operator a << endl; priority_queue , cmp2 > q; for (int i = 0; i < 10; i++) { q.push(rand()%20); } while (!q.empty()) { cout << q.top() << " "; q.pop(); } cout <