STL priority实例
生活随笔
收集整理的這篇文章主要介紹了
STL priority实例
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
按順序輸出序列:
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 }程序運(yùn)行結(jié)果!
本文轉(zhuǎn)自博客園xingoo的博客,原文鏈接:STL priority實(shí)例,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原博主。總結(jié)
以上是生活随笔為你收集整理的STL priority实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: idea 中使用@Autowired注入
- 下一篇: have sb do / have sb