您的位置:首页 > 其它

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

2018-03-29 17:01 260 查看
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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐