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

优先队列

时间:2017-11-06 13:57:30      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:std   tor   namespace   stream   ace   bre   using   else   while   

 

/*

num = q.top();

其余同队列

定义:

//priority_queue<int,vector<int>,less<int> > pque;//less<int>  greater<int>后面不加括号
   priority_queue<int,vector<int>,cmp> pque;

*/

#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<queue>
using namespace std;
int n,m;
int num;
struct cmp
{
    bool operator()(int &a,int &b)
    {
        return a<b;
    }

};
priority_queue<int,vector<int>,cmp> que;

int main()
{
    int i,j;
    while(1){
      cin>>n>>m;
      if(n==0&&m==0)
         break;
    for(i=0;i<n;i++)
    {
        cin>>num;
        que.push(num);
    }

      for(j=0;j<m;j++)
      {
          int top=que.top();
          que.pop();
          if(j==0) cout<<top;
          else cout<<" "<<top;
      }

        cout<<endl;

    }
    return 0;
}

优先队列

标签:std   tor   namespace   stream   ace   bre   using   else   while   

原文地址:http://www.cnblogs.com/unknownname/p/7792692.html

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