c++STL:priority_queue(优先队列)
作者:野牛程序员:2025-11-10 09:20:02C++阅读 2226
c++STL:priority_queue(优先队列)
✅ STL:priority_queue(优先队列)
✅ C++98 模板
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
// 默认大根堆(最大值优先)
priority_queue<int> pq;
// 插入元素
pq.push(5);
pq.push(1);
pq.push(9);
// 取堆顶 + 弹出
while(!pq.empty()){
cout << pq.top() << " ";
pq.pop();
}
cout << "\n";
return 0;
}✅ 输入样例
(无输入)
✅ 输出样例
9 5 1
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

- 上一篇:c++Kruskal 最小生成树
- 下一篇:c++数据结构:deque(双端队列)
