码迷,mamicode.com
首页 > 其他好文 > 详细

优先级队列-堆-STL实现

时间:2020-02-05 16:31:29      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:ios   如何   实现   EAP   space   names   return   code   main   

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <queue>
 4 
 5 using namespace std;
 6 
 7 // 默认是最大堆
 8 //
 9 
10 int main()
11 {
12     priority_queue<int> heap;
13     heap.push(3);
14     heap.push(1);
15     heap.push(5);
16     heap.push(4);
17 
18     while(!heap.empty())
19     {
20         cout<<heap.top()<<endl;
21         heap.pop();
22     }
23 
24 
25     // 如何实现最小堆?
26     priority_queue<int,vector<int>,greater<int>> heap2;
27     heap2.push(2);
28     heap2.push(4);
29     heap2.push(6);
30     heap2.push(1);
31     heap2.push(5);
32 
33     while(!heap2.empty())
34     {
35         cout<<heap2.top()<<endl;
36         heap2.pop();
37     }
38     return 0;
39 }

 

优先级队列-堆-STL实现

标签:ios   如何   实现   EAP   space   names   return   code   main   

原文地址:https://www.cnblogs.com/jishuren/p/12264099.html

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