码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-03-20 20:36:06      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:top   pre   比较   style   c++   排序   div   gre   cout   

 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 */

 

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

标签:top   pre   比较   style   c++   排序   div   gre   cout   

原文地址:https://www.cnblogs.com/zhangqiling/p/12534211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!