0001 /****************************************************************************************** 0002 * BinNode状态与性质的判断 0003 ******************************************************************************************/ 0004 #define IsRoot(x) ( ! ( (x).parent ) ) 0005 #define IsLChild(x) ( ! IsRoot(x) && ( & (x) == (x).parent->lc ) ) 0006 #define IsRChild(x) ( ! IsRoot(x) && ( & (x) == (x).parent->rc ) ) 0007 #define HasParent(x) ( ! IsRoot(x) ) 0008 #define HasLChild(x) ( (x).lc ) 0009 #define HasRChild(x) ( (x).rc ) 0010 #define HasChild(x) ( HasLChild(x) || HasRChild(x) ) //至少拥有一个孩子 0011 #define HasBothChild(x) ( HasLChild(x) && HasRChild(x) ) //同时拥有两个孩子 0012 #define IsLeaf(x) ( ! HasChild(x) ) 0013 0014 /****************************************************************************************** 0015 * 与BinNode具有特定关系的节点及指针 0016 ******************************************************************************************/ 0017 #define sibling( p ) ( IsLChild( * (p) ) ? (p)->parent->rc : (p)->parent->lc ) /*兄弟*/ 0018 #define uncle( x ) ( sibling( (x)->parent ) ) /*叔叔*/ 0019 #define FromParentTo( x ) /*来自父亲的引用*/ \ 0020 ( IsRoot(x) ? _root : ( IsLChild(x) ? (x).parent->lc : (x).parent->rc ) )