[b]二叉树的高度[/b]
图(1)
[img]http://baby69yy2000.iteye.com/upload/picture/pic/10722/abff40c6-4a67-3d23-a922-0c7c7cd5ffaf.jpg[/img]
......
图(1)
[img]http://baby69yy2000.iteye.com/upload/picture/pic/10722/abff40c6-4a67-3d23-a922-0c7c7cd5ffaf.jpg[/img]
/**用后根遍历求二叉树的高度*/
public static <T> int height(TNode<T> t) {
if (t == null)
return -1;
else {
int depL = height(t.left);
int depR = height(t.right);
if(depL > depR)
return depL + 1;
else
return depR + 1;
}
结果: Height = 2
......