求二叉树的高度/销毁一颗二叉树

int  HeightOfBinatyTree1(BinaryTreeNode* pRoot) //二叉树的高度
{
    if (pRoot == NULL)
        return 0;
    int m = HeightOfBinatyTree1(pRoot->_pLeft);
    int n = HeightOfBinatyTree1(pRoot->_pRight);
    return (m>n)? (m+1):(n+1);
}

void Destory(BinaryTreeNode*& pRoot)//销毁二叉树
{
    if (pRoot == NULL)
        return ;
    if (pRoot->_pLeft)
        Destory(pRoot->_pLeft);
    if (pRoot->_pRight)
        Destory(pRoot->_pRight);
    delete(pRoot);
    pRoot = NULL;

}



猜你喜欢

转载自blog.csdn.net/lu_1079776757/article/details/79745608