1 Star 0 Fork 0

非启鹏程/c++

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
priority_queue.cpp 859 Bytes
一键复制 编辑 原始数据 按行查看 历史
非启鹏程 提交于 2022-04-26 09:16 +08:00 . add STL/queue/priority_queue.cpp.
#include <queue>
int main()
{
// 默认按照小于方式比较, 创建的是大堆
priority_queue<int> q;
q.push(7);
q.push(1);
q.push(4);
q.push(9);
q.push(2);
q.push(6);
q.push(8);
q.push(3);
q.push(5);
q.push(0);
cout << q.top() << endl;
cout << q.size() << endl;
q.pop();
q.pop();
q.pop();
cout << q.top() << endl;
cout << q.size() << endl;
return 0;
}
#include <functional>
int test()
{
// 要创建小堆---必须要按照大于的方式比较
priority_queue<int,vector<int>, greater<int>> q;
q.push(7);
q.push(1);
q.push(4);
q.push(9);
q.push(2);
q.push(6);
q.push(8);
q.push(3);
q.push(5);
q.push(0);
cout << q.top() << endl;
cout << q.size() << endl;
q.pop();
q.pop();
q.pop();
cout << q.top() << endl;
cout << q.size() << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/dunqipeng/c1.git
git@gitee.com:dunqipeng/c1.git
dunqipeng
c1
c++
master

搜索帮助