天天看點

求二叉樹的高度/銷毀一顆二叉樹-->Destroy(Node* root)

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

void Destory(BinaryTreeNode*& pRoot)//銷毀二叉樹
{
    if (pRoot == NULL)
        return ;
    if (pRoot->_pLeft)
        Destory(pRoot->_pLeft);
    if (pRoot->_pRight)
        Destory(pRoot->_pRight);

    delete(pRoot);
    pRoot = NULL;

}
           

繼續閱讀