首页 > 其他 > 详细

关于优先队列浅析(priority_queue)

时间:2019-03-28 00:29:12      阅读:179      评论:0      收藏:0      [点我收藏+]


关于优先队列中的自定义函数cmp以及结构体的优先形式 后期会更新差不多这个周日吧

下面废话不多说直接上程序  

注释的很明白

这个博客我就是当作笔记来写的,同样也给大家提供点便利嘛~

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define nn 100000005
 5 #include<cstdio>
 6 #include<queue>
 7 using namespace std;
 8 queue<int > q;
 9 //  greater 小到大 less  大到小
10 //q.pop() 弹出最优元素 q.push()送入元素
11 //q.empty()判断队列是否为空
12 //q.size()  返回队列的长度
13 priority_queue<int,vector<int>,greater<int> > qq;
14 priority_queue<int,vector<int>,less<int> >qw;
15 int main()
16 {
17     int a[4]= {16,6,8,1};
18 
19     for(int i=0; i<4; i++)
20         qq.push(a[i]);
21 
22     for(int i=0; i<4; i++)
23     {
24         cout<<qq.top()<<endl;
25         qq.pop();
26     }
27 
28     for(int i=0; i<4; i++)
29         qw.push(a[i]);
30     cout<<qw.size()<<endl;
31 /*    for(int i=0; i<4; i++)
32         {
33             cout<<qw.top()<<endl;
34             qw.pop();
35          }                          */
36     cout<<endl;
37     while(!qw.empty())
38     {
39         cout<<qw.top()<<endl;
40         qw.pop();
41     }
42     cout<<endl<<qw.size()<<endl;
43     return 0;
44 }

  

关于优先队列浅析(priority_queue)

原文:https://www.cnblogs.com/maxv/p/10611982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!