欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

STL priority实例

发布时间:2025/7/14 编程问答 42 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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 }

程序运行结果!

本文转自博客园xingoo的博客,原文链接:STL priority实例,如需转载请自行联系原博主。

总结

以上是生活随笔为你收集整理的STL priority实例的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。