0001 auto Height = [](auto x) { return x ? x->height : 0; }; //nullptr的黑高度为0 0002 auto Stature = [](auto x) { return Height(x) + IsBlack(x); }; //黑身高 = 黑高度 + 颜色 0003 auto RbtBalanced = [](auto x) { return !x || (Stature(x->lc) == Stature(x->rc)); }; //黑平衡 0004 template <typename T> int BinNode<T>::updateHeight() { //更新节点黑高度 0005 return height = max(Stature(lc), Stature(rc)); //孩子们的身高通常相等 0006 } //但在双黑缺陷时则不然,唯如此方能在修复过程中正确地更新当前节点的黑高度 0007 template <typename T> void BinNode<T>::updateHeightAbove() //更新当前节点及其祖先的黑高度 0008 { for (BNP<T> x = this; x; x = x->parent) x->updateHeight(); }