STL heap

我不会堆了
STL heap 默认建立大根堆
可以重载伪函数比如struct cmp { inline bool operator () (const node & x, const node & y) const { return x.val > y.val; } };
假如有个vector
vector<int>nums;
make_heap(nums.begin(),nums.end(),cmp());用于建堆 可以做到(O(n))
nums.push_back(x);push_heap(nums.begin(),nums.end(),cmp());可以加入元素
pop_heap(nums.begin(),nums.end(),cmp());nums.pop_back();可以删除堆顶

原文地址:https://www.cnblogs.com/WinterSpell/p/13323278.html