0001 auto Height = [](auto x) //简化描述 0002 { return x ? x->height : -1; }; //空树高度为-1 0003 template <typename T> int BinNode<T>::updateHeight() //更新当前节点高度 0004 { return height = max(Height(lc), Height(rc)) + 1; } 0005 template <typename T> void BinNode<T>::updateHeightAbove() //更新当前节点及其祖先的高度 0006 { for (BNP<T> x = this; x; x = x->parent) x->updateHeight(); } //可优化