数据结构与算法-第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 }
原文地址:https://www.cnblogs.com/shamgod/p/5295580.html