0001 template <typename T> 0002 constexpr inline bool HeightUpdated(BNP<T> x) /* 常规BST高度更新条件 */ \ 0003 { return x->height == max(Height(x->lc), Height(x->rc)) + 1; } 0004 0005 //BinTree节点 0006 template <typename T> void UniPrint::p(BNP<T> node) { 0007 p(node->data); //数值 0008 printf("(%2d)", node->height); //高度、黑高度、NPL 0009 printf(//父子链接指针 0010 (node->lc && node != node->lc->parent) || 0011 (node->rc && node != node->rc->parent) ? 0012 "@" : " " 0013 ); 0014 #if defined(DSA_REDBLACK) 0015 printf(node->color ? "B" : " "); //节点颜色(忽略红节点) 0016 #endif 0017 0018 //父子(黑)高度、NPL匹配 0019 #if defined(DSA_PQ_COMPLHEAP) 0020 //高度不必匹配 0021 #elif defined(DSA_PQ_LEFTHEAP) 0022 printf(//NPL 0023 (node->rc && (node->npl != node->rc->npl + 1)) || 0024 (node->lc && (node->npl > node->lc->npl + 1)) ? 0025 "%%" : " " 0026 ); 0027 #elif defined(DSA_REDBLACK) 0028 printf(RbtBalanced(node) ? " " : "!"); //黑高度 0029 #else 0030 printf(HeightUpdated(node) ? " " : "!"); //(常规)高度 0031 #endif 0032 0033 //左右平衡 0034 #if defined(DSA_AVL) 0035 if (!AvlBalanced(node)) printf("X"); //AVL失衡 0036 else if (0 < BalFac(node)) printf("\&#92;&#34;); //左偏 0037 else if (BalFac(node) < 0) printf("/"); //右偏 0038 else printf("-"); //AVL平衡 0039 #elif defined(DSA_REDBLACK) 0040 int hL = node->lc ? node->lc->height + node->lc->color : 1; 0041 int hR = node->rc ? node->rc->height + node->rc->color : 1; 0042 if (hL > hR) printf("/"); //左偏 0043 else if (hL < hR) printf("/"); //右偏 0044 else printf("-"); //RB平衡 0045 #else 0046 //平衡无所谓 0047 #endif 0048 }