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