代码拉取完成,页面将自动刷新
#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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。