码迷,mamicode.com
首页 > 其他好文 > 详细

优先队列

时间:2015-03-28 08:59:02      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:acm

优先队列

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct cmp
  4. {
  5. bool operator() (const int a, const int b) const{
  6. return a%10 > b%10;///定义个位数小的优先级大
  7. }
  8. };
  9. int main()
  10. {
  11. priority_queue<int, vector<int>, cmp> pq;
  12. for(int i=0; i<5; i++)
  13. {
  14. int a;
  15. cin>>a;
  16. pq.push(a);
  17. }
  18. while(!pq.empty())
  19. {
  20. cout<<pq.top()<<endl;
  21. pq.pop();
  22. }
  23. return 0;
  24. }
  1. priority_queue<int, vector<int>, greater<int> >则表示越小的整数优先级越大

优先队列

标签:acm

原文地址:http://blog.csdn.net/dojintian/article/details/44682505

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!