priority_queue 自定义比较函数
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
using namespace std;
struct Node{
int x;
int 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;
else return a.x < b.x ;
}
};
/*
struct cmp{
bool operator() ( Node a, Node b )
{
if( a.x== b.x ) return a.y> b.y;
return a.x> b.x;
}
};*/
int main()
{
priority_queue <Node, vector<Node>, cmp > q;
for(int i= 0; i< 10; ++i )
{
q.push(Node(i,10-i));
}
while( !q.empty())
{
cout << q.top().x << ' ' << q.top().y << endl;
q.pop();
}
return 0;
}