1 #include<bits/stdc++.h>2 using namespace std;3 struct node{4 int x,y,z;5 node(int a,int b,int c):x(a),y(b),z(c){}6 bool operator < (const node &rhs) const{7 return x < rhs.x;//按照x来定义优先顺序8 }9 };10 int main(){11 priority_queue<node> q;12 q.push(node(3,4,5));13 q.push(node(4,5,6));14 q.push(node(2,3,4));15 while(!q.empty()){16 node t = q.top();17 q.pop();18 cout << t.x << \" \" << t.y << \" \" << t.z << endl;19 }20 return 0;21 }22 /*23 >24 结果:25 2 3 426 3 4 527 4 5 628 <29 结果:30 4 5 631 3 4 532 2 3 433 结论:34 priority_queue中重载运算符与sort中重载运算符刚好相反35 */