1. 统计节点数
1 int CountNodes ( SearchTree T ) { 2 if ( T == NULL) 3 return 0; 4 else 5 return 1 + CountNodes ( T->Left) + CountNodes (T->Right); 6 }
2.统计叶子树
1 int CountLeaves (SearchTree T) { 2 if (T == NULL) 3 return 0; 4 else if (T->Left == NULL && T->Right == NULL) 5 return 1; 6 else return CountLeaves (T->Right) + CountLeaves (T -> Left); 7 }
3.统计左右孩子都存在的双亲节点数
int CountFull (SearchTree T) { if ( T == NULL) return 0; else return (T->Right != NULL && T->Left != NULL) + CountFull (T->Left) + CountFull (T->Right); }
以上函数已经更新到 tree.h 中。