zoukankan      html  css  js  c++  java
  • 计算二叉树的深度

    先遍历二叉树的左子树的深度,然后再遍历二叉树右子树的深度。最后判断左子树和右子树的深度,如果左子树比右子树深则返回左子树深度+1,否则返回右子树深度+1。

    /* 初始条件: 二叉树T存在。操作结果: 返回T的深度 */

    int BiTreeDepth(BiTree T)
    {
     int i,j;
        if(!T)
      return 0;
     if(T->lchild)
      i=BiTreeDepth(T->lchild); // 左子树深度
     else
      i=0;
     if(T->rchild)
      j=BiTreeDepth(T->rchild);  // 右子树深度
     else
      j=0;
     return i>j?i+1:j+1;
    }
  • 相关阅读:
    HDU 4005 The war
    #undef
    [转载] #define new DEBUG_NEW
    [转载]常用正则表达式
    [百科]
    [转载]
    [转载]
    [转载]
    [百科]
    [转载]VC6中的文件后缀
  • 原文地址:https://www.cnblogs.com/stone531/p/4559732.html
Copyright © 2011-2022 走看看