头文件:#include<queue>
//升序队列
prioriry_queue<int,vector<int>,greater<int>> q;
//降序队列
priority_queue<int,vectot<int>,less<int>> q;
几个方法:
top();访问对头元素,有返回值
pop();弹出对头元素,无返回值的
size();队列元素个数
push();将元素插入队尾
empty();队列是否为空
注意:
priority_queue(),默认按照从小到大排列。所以top()返回的是最大值而不是最小值!
使用greater<>后,数据从大到小排列,top()返回的就是最小值而不是最大值!
如果使用了第三个参数,那第二个参数不能省,用作保存数据的容器!!!!