template < class Type, class Container=vector<Type>, class Compare=less<typename Container::value_type> > class priority_queue
template <class T> struct less { bool operator() (const T& x, const T& y) const {return x<y;} typedef T first_argument_type; typedef T second_argument_type; typedef bool result_type; };
struct Node{ int x, y; Node( int a= 0, int b= 0 ): x(a), y(b) {} }; struct cmp{ bool operator() ( Node a, Node b ){ if( a.x== b.x ) return a.y> b.y; return a.x> b.x; } }; priority_queue<Node, vector<Node>, cmp> q;注意,这个堆是小顶堆。实际上,我们是按照operator ()的操作,将新添加的元素放在堆底的。
原文地址:http://blog.csdn.net/trochiluses/article/details/39589879