STL-priority_queue(ACM)
1.无法访问v.front()、v.back()
2.是一个 堆,默认为大根堆,改造后为小根堆
大根堆
重构函数(默认)(大根堆)
priority_queue<int> v;
基本操作
v.top() // 访问堆顶元素 v.push() // 加入堆顶 v.pop() // 弹出堆顶元素
(堆顶的优先级是最高的)
// 遍历堆(从大到小输出) while (!v.empty()) { printf("%d\n", v.top()); v.pop(); }
小根堆
重构函数(板子)
priority_queue<int, vector<int>, greater<int>> v;
遍历堆(从小到大输出,小根堆特性:优先级最小在堆顶)
while (!v.empty()) { cout << v.top() << endl; v.pop(); }

浙公网安备 33010602011771号