zoukankan      html  css  js  c++  java
  • 数据结构与算法-第12章二叉树和其他树-003求二叉树的高度

    The code to find the tree height using a postorder traversal is given below.

     1 public class BinaryTreeHeight
     2 {
     3    /** @return tree height */
     4    public static int height(BinaryTreeNode t)
     5    {
     6       if (t != null)
     7       {// nonempty tree
     8          // find height of left subtree
     9          int hLeft = height(t.leftChild);
    10 
    11          // find height of right subtree
    12          int hRight = height(t.rightChild);
    13 
    14          // return overall height
    15          return Math.max(hLeft, hRight) + 1;
    16       }
    17       else
    18          return 0;
    19    }
    20 }
  • 相关阅读:
    反射
    定义类
    集合list,set,Map
    API util
    进程与多线程
    泛型
    API string
    JDBC存储过程
    预处理
    JDBC
  • 原文地址:https://www.cnblogs.com/shamgod/p/5295580.html
Copyright © 2011-2022 走看看