1.优先队列基于堆排序。
2.优先队列自动排序,优先级高的元素先出队列。
2.1 如果是整形,降序排列(例如:输出为:8 5 1)。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
int main()
{
priority_queue<int>p;
p.push(5);
p.push(8);
p.push(1);
while(!p.empty())
{
cout<<p.top()<<endl;
p.pop();
}
return 0;
}
2.2 不是整形,则看优先级别,优先级可自己设定(例如:)。
struct node
{
int x,y;
bool operator < (const node & a) const
{
return x>a.x;//降序
//return x<a.x;升序
}
};
3.实现原理:

1万+

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



