STL:priority_queue

版权声明:本博客为记录本人学习过程而开,内容大多从网上学习与整理所得,若侵权请告知! https://blog.csdn.net/Fly_as_tadpole/article/details/83188350

模板原型:priority_queue<T,Sequence,Compare>
T:存放容器的元素类型
Sequence:实现优先级队列的底层容器,默认是vector<T>
Compare:用于实现优先级的比较函数,默认是functional中的less<T>,大顶堆
常用的操作如下:

empty()   如果优先队列为空,则返回真
pop()      删除第一个元素(队首删除)
push()    加入一个元素(队尾追加)
size()    返回优先队列中拥有的元素的个数
top()      返回优先队列中有最高优先级的元素(队首元素)

priority_queue<int> p  大顶堆

priority_queue<int,vector<int>,less<int>>p  大顶堆

priority_queue<int,vector<int>,greater<int>>p  小顶堆


 

猜你喜欢

转载自blog.csdn.net/Fly_as_tadpole/article/details/83188350