详细的代码可见github:
https://github.com/AbitGo/myClassWork/tree/master/workspace_ds
两种非递归方法
public int getDepth(BiTreeNode t) {
if (t != null) {
int lDepth = getDepth(t.lchild);
int rDepth = getDepth(t.rchild);
return 1 + (lDepth > rDepth ? lDepth : rDepth);
}
return 0;
}
public int getDepth1(BiTreeNode t) {
if (t == null) {
return 0;
} else if (t.rchild == null && t.lchild == null) {
return 1;
} else {
return 1 + (getDepth1(t.lchild) > getDepth1(t.rchild) ? getDepth1(t.lchild) : getDepth1(t.rchild));
}
}