priority_queue 用法

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 priority_queue<int>q;  //从大到小
 4 priority_queue<int,vector<int>,greater<int> >Q;   //从小到大
 5 //结构体元素类型:
 6 struct node
 7 {
 8     int x,y,z;
 9     friend bool operator <(const node &a,const node &b){
10     return a.x>b.x;//(小顶)
11     //(return a.x<b.x;大顶)
12    }
13 };
14 priority_queue<node>QQ;
15 int main()
16 {
17     for(int i=1;i<=5;i++){
18         int tmp;
19         scanf("%d",&tmp);
20         q.push(tmp);
21         Q.push(tmp);
22     }
23     while(!q.empty()){
24 
25         printf("%d ",q.top());
26         q.pop();
27     }
28     printf("\n");
29     while(!Q.empty()){
30         printf("%d ",Q.top());
31         Q.pop();
32     }
33     printf("\n");
34     return 0;
35 }

 

原文链接: https://www.cnblogs.com/pangbi/p/12409232.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    priority_queue 用法

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/333434

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午9:10
下一篇 2023年3月1日 下午9:10

相关推荐