优先队列

#include <iostream>
#include <stdio.h>
#include<string.h>
#include <queue>
using namespace std;
struct node
{
    int a,b;
    friend bool operator <(node x,node y)
    {
        return x.a>y.a;  //如果为 >优先级小的先出队列  反之
    }
};
priority_queue<node> q;
int main()
{

    node a[10];

    for(int i=0; i<10; i++)
    {
        scanf("%d %d",&a[i].a,&a[i].b);
        q.push(a[i]);
        node b;
        b=q.top();
        printf(">>>%d %d
",b.a,b.b);
    }

    return 0;
}
</pre><pre name="code" class="cpp">



出队列按照一定优先级出队列 ,见下图



图一                                                                                                                                           图二

     


原文地址:https://www.cnblogs.com/coded-ream/p/7208015.html