Article From:https://www.cnblogs.com/FengZeng666/p/9971217.html
int Depth(BiTree T)/* depth*/
{
    if(T==NULL)
        return(0);
    return 1+(Depth(T->lchild)>Depth(T->rchild)? Depth(T->lchild):Depth(T->rchild));
//Choose the depth of the left and right children and add the root node layer to the depth.
}
void Long(BiTree T)
{
    if(T!=NULL)//When T is not empty
    {
        visit(T->data);//Access node
        if(Depth(T->lchild)>Depth(T->rchild))//Judge whether to go left or right
            Long(T->lchild);
        else
            Long(T->rchild);
    }
}
Depth is length. The following function calls the above function

 

Leave a Reply

Your email address will not be published. Required fields are marked *