优先队列

来源:互联网 发布:linux开机不启动防火墙 编辑:程序博客网 时间:2024/04/29 06:34



在普通队列的基础上 以权值大小执行进出队列的操作



#include<iostream>#include<queue>using namespace std;struct point{int x,y,step;friend bool operator <(point t1,point t2){//return t1.step>t2.step;   //从小到大return t1.step<t2.step;   //从大到小  与<相同 大顶堆 }};/*5 3 4 2 1 5*/priority_queue<point>Q;int main(){int n,i,j;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++){point t;scanf("%d",&t.step);Q.push(t);}point t;while(!Q.empty()){printf("\t%d\n",Q.top().step);Q.pop();}printf("\n");}return 0;}


原创粉丝点击