1重载"<"友元或非友元。
2定义个结构体作为Priority_queue的第三个参数。 (顺便了解了assert());
#include <bits/stdc++.h>
using namespace std;
#define mt make_tuple
struct cmp1
{
bool operator () (tuple<int,int,int>&a1,tuple<int,int,int>&a2) {
return get<0>(a1) > get<0>(a2);
}
};
int main()
{
priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,cmp1> pq;
pq.push(mt(1,2,3));
pq.push(mt(2,2,1));
pq.push(mt(0,1,1));
while(!pq.empty()) {
int x,y,z;
tie(x,y,z) = pq.top();
cout << x << " " << y << " " << z << endl;
pq.pop();
}
return 0;
}