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 4 26 3 4 5 27 4 5 6 28 < 29 结果: 30 4 5 6 31 3 4 5 32 2 3 4 33 结论: 34 priority_queue中重载运算符与sort中重载运算符刚好相反 35 */