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

  • 相关阅读:
    a*b高精度数组算法
    vscode plugins
    vscode keys
    vscode setting.jsonxx
    vscode settings.json
    webstorm keys
    vscode extensions
    vscode wechat settings.json
    vscode sass live compiler
    webstorm crack
  • 原文地址:https://www.cnblogs.com/hanxinle/p/7562653.html
Copyright © 2011-2022 走看看