1.进行合法性判断,也是递归结束的条件
2.递归求出左子树的高度
3.递归求出右子树的高度
4.比较左右两边高度大小,选择大的那个加上“根”节点,这里的根是相对于每一个子树/节点的。
5.返回最后的高度
int Depth(BiTNode * T)
{
int ret = 0;
int dep_left = 0, dep_right = 0;
if (T == NULL)
{
ret = 0;
return ret;
}
dep_left = Depth(T->lchild);
dep_right = Depth(T->rchild);
ret = 1 + (dep_left>dep_right?dep_left:dep_right);
return ret;
}