在普通队列的基础上 以权值大小执行进出队列的操作
#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;
}
424

被折叠的 条评论
为什么被折叠?



