优先队列

头文件为:#include<queue>

优先队列的结构体定义:

                                           

struct node
{
    int x;
    friend bool operator<(node a,node b)
    {
        return a.x<b.x;//大的先输出
    }
}a,b;

#include<iostream>
#include<queue>
using namespace std;
struct node
{
    int x;
    friend bool operator<(node a,node b)
    {
        return a.x<b.x;//大的先输出
    }
}a,b;
int main()
{
    priority_queue<node>q;//
    cin>>a.x>>b.x;
    q.push(a);
    q.push(b);
    node m;
    m=q.top();
    q.pop();
    cout<<m.x<<endl;
     m=q.top();
    cout<<m.x<<endl;
}


posted @ 2017-03-06 20:48  X_na  阅读(127)  评论(0)    收藏  举报