using namespace std;
struct Node {
int x;
int y;
Node(int xx, int yy) : x(xx), y(yy) {}
// priority_queue默認(rèn)大根堆倔喂,采用less<int>借宵,與map從小到大不一樣;優(yōu)先隊(duì)列默認(rèn)按照最大優(yōu)先級(jí)键菱,所以需要重構(gòu)<
// 該例子充坑,按照X從大到小排序熔任,如果x相同拆融,則按照y從小到大排列
bool operator < (const Node &b) const
{
if (x == b.x) {
return y > b.y; // 以b為對(duì)象蠢琳,從小到大;
}
return x < b.x; // 以b為對(duì)象镜豹,順著從大到邪列搿;
}
};
int main()
{
priority_queue<Node> que;
Node node1 = {1, 5};
Node node2 = {1, 2};
Node node3 = {3, 6};
que.push(node1);
que.push(node2);
que.push(node3);
while (que.empty() != true) {
cout<<que.top().x<<que.top().y<<endl;
que.pop();
}
return 0;
}