pair类型在priority_queue中是如何排序的


 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int,int> node_pair;
 4 int main(){
 5     priority_queue<node_pair,vector<node_pair>,greater<node_pair> > q;
 6     q.push(make_pair(10,5));
 7     q.push(make_pair(5,15));
 8     q.push(make_pair(5,10));
 9     while(!q.empty()){
10         node_pair t = q.top();
11         q.pop();
12         cout << t.first << " " << t.second << endl;
13     }
14     return 0;
15 }
16 
17 /*
18     输出:
19         5 10
20         5 15
21         10 5 
22     总结:
23         pair类型放入优先队列中总是先比较first的大小,相同在比较second的大小 
24 */

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM