技术笔记
本博客记录踩坑脱坑、早年知识归纳. 新博客常常更新: https://hanxinle.github.io

导航

 

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 }
int CountNodes ( SearchTree T )

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 }
int CountLeaves (SearchTree T )

3.统计左右孩子都存在的双亲节点数

int CountFull  (SearchTree T)    {
    if ( T == NULL)   
        return 0;
    else return (T->Right != NULL && T->Left != NULL) +
                 CountFull (T->Left) + CountFull (T->Right);
}
int CountFull (SearchTree T)

 

 

以上函数已经更新到 tree.h 中。

posted on 2017-09-20 17:25  九品加  阅读(258)  评论(0编辑  收藏  举报