您的位置:首页 > 其它

优先队列

2016-03-29 12:13 162 查看
#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\n",b.a,b.b);
}

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


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

图一                                                                                                                                           图二

     



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: