首页 > 编程知识 正文

怎么算二叉树的深度,二叉树递归遍历代码

时间:2023-05-06 05:21:54 阅读:160289 作者:1270

二叉树深度的递归算法

输入深度(btree root ) . {

intldepth,rdepth;

if (! 路线)

返回0;

else.{

LDepth=Depth(root-Lchild );

rdepth=depth(root-rchild );

if(Ldepth=Rdepth(/左右子树的最大深度加1返回

returnldepth 1;

else

returnrdepth 1;

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。