Cpp实现:
#include
#include
using namespace std;
struct Node
{
int a, b;
Node() {}
Node(int a, int b) : a(a), b(b) {}
bool operator>(const Node& t) const
{
if (a > t.a) return true;
else if (a < t.a) return false;
else b > t.b;
}
bool operator
{
if (a < t.a) return true;
else if (a > t.a) return false;
else return b < t.b;
}
};
priority_queue, greater> pq;
//priority_queue pq;
int main()
{
pq.push(Node(2, 3));
pq.push(Node(2, 2));
pq.push(Node(1, 1));
// pq.push(Node(1, 1));
// pq.push(Node(2, 2));
// pq.push(Node(2, 3));
while (!pq.empty())
{
printf("%d %d\n", pq.top().