二叉树深度的递归算法
int depth(BTree root)...{
int ldepth,rdepth;
if(!root)
return 0;
else...{
ldepth = depth(root->lchild);
rdepth = depth(root->rchild);
if(ldepth >= rdepth) //取左右子树深度的最大值加一返回
return ldepth+1;
else
return rdepth+1;
}
二叉树深度的递归算法
int depth(BTree root)...{
int ldepth,rdepth;
if(!root)
return 0;
else...{
ldepth = depth(root->lchild);
rdepth = depth(root->rchild);
if(ldepth >= rdepth) //取左右子树深度的最大值加一返回
return ldepth+1;
else
return rdepth+1;
}