用C++标准库的方式使用堆

简介

RT

参考链接

https://github.com/lishaohsuai/digital_geo/blob/master/Surface_Framework_VS2017/SurfaceMeshProcessing/mySimpleMesh.h
https://blog.csdn.net/weixin_42105432/article/details/93518786

priority_queue 实现

#include<queue>
#include<vector>
std::priority_queue<int> big_heap;   // 构造一个默认最大堆
std::priority_queue<int, std::vector<int>, std::greater<int> > small_heap; //构造一个最小堆

mutiset 实现

struct vert_pair_CMP {
  bool operator() (const myPair &a, const myPair &b) {
    return a.error < b.error;
  }
};
typedef std::multiset<myPair, vert_pair_CMP> PairHeap;//定义堆
PairHeap heap;

优缺点

个人更喜欢multiset, 因为似乎可以使用for(auto it :multiset ..) 进行遍历
但无疑 priority_queue 更简单.

Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/14679823.html