zoukankan      html  css  js  c++  java
  • 算法(7) —— 统计树的特定点

    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 中。

  • 相关阅读:
    [转] Spring
    测试公式
    lexicalized Parsing
    MLN Alchemy
    Pedro domingos
    MLE & MAP
    Learning
    ProbCog mlnlearn的探索
    MLN 讨论 —— inference
    Mathjax与LaTex公式简介
  • 原文地址:https://www.cnblogs.com/hanxinle/p/7562653.html
Copyright © 2011-2022 走看看