STL priority实例

复制代码
 1 #include <iostream>
 2 #include <vector>
 3 #include <queue>
 4 #include <functional>
 5 #include <string>
 6 using namespace std;
 7 template <typename PriorityQueue>
 8 void dumpContents(const string & msg,PriorityQueue & pq)
 9 {
10     cout<<msg<<":"<<endl;
11     while(!pq.empty())
12     {
13         cout<<pq.top()<<endl;
14         pq.pop();
15     }
16 }
17 int main()
18 {
19     priority_queue<int> maxPQ;
20     priority_queue<int,vector<int>,greater<int> > minPQ;
21 
22     minPQ.push(4);
23     minPQ.push(3);
24     minPQ.push(5);
25     maxPQ.push(4);
26     maxPQ.push(3);
27     maxPQ.push(5);
28 
29     dumpContents("minPQ",minPQ);
30     dumpContents("maxPQ",maxPQ);
31 
32     return 0;
33 }
复制代码
posted @ 2017-05-19 22:01  罗志均  阅读(87)  评论(0编辑  收藏  举报
友情链接:回力 | 中老年女装 | 武汉英语培训机构 | 留学费用一览表 | 托福考试费用