0001 /****************************************************************************************** 0002 * BinTree节点 0003 ******************************************************************************************/ 0004 template <typename T> void UniPrint::p ( BinNodePosi<T> node ) { 0005 p ( node->data ); //数值 0006 /****************************************************************************************** 0007 * height & NPL 0008 ******************************************************************************************/ 0009 #if defined(DSA_LEFTHEAP) 0010 printf ( "(%2d)", node->npl ); //NPL 0011 #elif defined(DSA_BST) 0012 printf ( "(%2d)", node->height ); //高度 0013 #elif defined(DSA_AVL) 0014 printf ( "(%2d)", node->height ); //高度 0015 #elif defined(DSA_REDBLACK) 0016 printf ( "(%2d)", node->height ); //高度 0017 #elif defined(DSA_SPLAY) 0018 printf ( "(%2d)", node->height ); //高度 0019 #endif 0020 /****************************************************************************************** 0021 * 父子链接指针 0022 ******************************************************************************************/ 0023 printf ( 0024 ( node->lc && node != node->lc->parent ) || 0025 ( node->rc && node != node->rc->parent ) ? 0026 "@" : " " 0027 ); 0028 /****************************************************************************************** 0029 * 节点颜色 0030 ******************************************************************************************/ 0031 #if defined(DSA_REDBLACK) 0032 printf ( node->color == RB_BLACK ? "B" : " " ); //(忽略红节点) 0033 #endif 0034 /****************************************************************************************** 0035 * 父子(黑)高度、NPL匹配 0036 ******************************************************************************************/ 0037 #if defined(DSA_PQ_COMPLHEAP) 0038 //高度不必匹配 0039 #elif defined(DSA_PQ_LEFTHEAP) 0040 printf ( //NPL 0041 ( node->rc && ( node->npl != 1 + node->rc->npl ) ) || 0042 ( node->lc && ( node->npl > 1 + node->lc->npl ) ) ? 0043 "%%" : " " 0044 ); 0045 #elif defined(DSA_REDBLACK) 0046 printf ( BlackHeightUpdated ( node ) ? " " : "!" ); //黑高度 0047 #else 0048 printf ( HeightUpdated ( node ) ? " " : "!" ); //(常规)高度 0049 #endif 0050 /****************************************************************************************** 0051 * 左右平衡 0052 ******************************************************************************************/ 0053 #if defined(DSA_AVL) 0054 if ( !AvlBalanced ( node ) ) printf ( "X" ); //AVL平衡 0055 else if ( 0 < BalFac ( node ) ) printf ( "\&#92;&#34; ); //AVL平衡 0056 else if ( BalFac ( node ) < 0 ) printf ( "/" ); //AVL平衡 0057 else printf ( "-" ); //AVL平衡 0058 #elif defined(DSA_REDBLACK) 0059 if ( !Balanced ( node ) ) printf ( "X" ); //RB平衡 0060 else if ( 0 < BalFac ( node ) ) printf ( "\&#92;&#34; ); //RB平衡 0061 else if ( BalFac ( node ) < 0 ) printf ( "/" ); //RB平衡 0062 else printf ( "-" ); //RB平衡 0063 #else 0064 //平衡无所谓 0065 #endif 0066 }