0001 #define npl height //假借高度,用作NPL 0002 auto NPL = [](auto x) { return x ? x->npl : 0; }; //统一处置nullptr 0003 template <typename T> struct LeftHeap : public PQ<T>, public BinTree<T> { //左式堆 0004 LeftHeap(T* E, int n) //批量构造:可改进为Floyd算法 0005 { for (int i = 0; i < n; i++) insert(E[i]); } 0006 LeftHeap(LeftHeap& A, LeftHeap& B) { //通过融合的构造 0007 _root = meld(A._root, B._root); _size = A._size + B._size; 0008 A._root = B._root = nullptr; A._size = B._size = 0; 0009 } 0010 void insert(T); T delMax(); //插入与删除 0011 T& getMax() { return _root->data; } //堆顶即是最大元素 0012 }; //LeftHeap