STL queue(2)

View Code
 1 #include<iostream>
2 #include<queue>
3
4 int main()
5 {
6
7 using namespace std;
8
9 priority_queue<int,vector<int>> pq;//默认是vector 最大值优先级队列
10
11 //谓词
12 priority_queue<int,deque<int>,greater<int>> pq2; //加上greater 就是最小值优先级队列
13
14 pq.push(10);
15 pq.push(5);
16 pq.push(-1);
17 pq.push(20);
18
19 //最大的在最前面
20
21 cout << "优先级队列里共有 " << pq.size() << "个数据" << endl;
22
23 while(!pq.empty())
24
25 {
26
27 cout <<"从优先级队列里删除: " << pq.top() << endl;
28
29 pq.pop();
30
31
32 }
33
34 pq2.push(10);
35 pq2.push(5);
36 pq2.push(-1);
37 pq2.push(20);
38
39
40 while(!pq2.empty())
41
42 {
43
44 cout <<"从优先级队列里删除: " << pq2.top() << endl;
45
46 pq2.pop();
47
48
49 }
50
51
52 return 0;
53 }
posted @ 2012-03-27 23:32  uniquews  阅读(158)  评论(0编辑  收藏  举报