堆(模板)(优先队列实现)
作者:互联网
- 堆好麻烦直接偷懒用优先队列吧
- 优先小队列(堆顶为最小元)创建
priority_queue<int, vector<int>, greater<int>> q;
#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int>> q;
int n;
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int choice;
scanf("%d", &choice);
if (choice == 1)
{
int t;
scanf("%d", &t);
q.push(t);
}
else if (choice == 2)
{
printf("%d\n", q.top());
}
else
{
q.pop();
}
}
}
标签:priority,优先,greater,队列,queue,int,模板 来源: https://www.cnblogs.com/Wang-Xianyi/p/16536300.html