首页 > 其他 > 详细

优先队列

时间:2014-08-05 00:38:18      阅读:412      评论:0      收藏:0      [点我收藏+]
 1 #include <iostream>
 2 #include <vector>
 3 #include <queue>
 4 #include <functional>
 5 #include <string>
 6 using namespace std;
 7 
 8 // Empty the priority queue and print its contents.
 9 template <typename PriorityQueue>
10 void dumpContents( const string & msg, PriorityQueue & pq )
11 {
12     cout << msg << ":" << endl;
13     while( !pq.empty( ) )
14     {
15         cout << pq.top( ) << endl;
16         pq.pop( );
17     }
18 }
19 
20 // Do some inserts and removes (done in dumpContents).
21 int main( )
22 {
23     priority_queue<int>                          maxPQ;
24     priority_queue<int,vector<int>,greater<int>> minPQ;
25 
26     minPQ.push( 4 ); minPQ.push( 3 ); minPQ.push( 5 );
27     maxPQ.push( 4 ); maxPQ.push( 3 ); maxPQ.push( 5 );
28 
29     dumpContents( "minPQ", minPQ );
30     dumpContents( "maxPQ", maxPQ );
31 
32     return 0;
33 }

 

优先队列,布布扣,bubuko.com

优先队列

原文:http://www.cnblogs.com/dracohan/p/3891237.html

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