int Depth(BiTree T)/* 深度 */
{
    if(T==NULL)
        return(0);
    return 1+(Depth(T->lchild)>Depth(T->rchild)? Depth(T->lchild):Depth(T->rchild));
//选择左右孩子深度高的然后加上根节点这一层就是深度了
}
void Long(BiTree T)
{
    if(T!=NULL)//在T不为空的情况下
    {
        visit(T->data);//访问节点
        if(Depth(T->lchild)>Depth(T->rchild))//判断往左走还是往右走
            Long(T->lchild);
        else
            Long(T->rchild);
    }
}
深度就是长度,下面的函数要调用上面的函数

 

相关文章:

  • 2022-01-06
  • 2021-06-01
  • 2022-03-06
  • 2021-12-31
  • 2021-08-14
  • 2021-07-16
  • 2022-12-23
  • 2021-07-10
猜你喜欢
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案