1. 头文件
#include<queue>
2. 默认写法(降序排序)
//对于基本类型,默认是大顶堆
priority_queue<int> a;
//等同于 priority_queue<int,vector<int>,less<int> > a;
3. 小顶堆(升序排序)
priority_queue<int,vector<int>,greater<int> > a;
4. 优先队列基本操作
- top访问队头元素
- empty队列是否为空
- size返回队列内元素个数
- push插入元素到队尾(并排序)
- emplace原地构造一个元素并插入队列
- pop弹出对头元素
- swap交换内容
priority_queue和queue不同的是我们可以自定义其中数据的优先级,让优先级高的排在队列前面,优先出队