c语言二叉树的删除

二叉树的删除程序,求源代码,能实现的

第1个回答  2012-03-26
int TreeDelete(TreeNode *root,EleType data) //删除二叉树的结点
{
TreeNode *delp;

if(!root) return 0;

delp=Find(root,data);
if(!delp) return 0;

if(delp==root)
{
Destroy(root);
printf("Destroy the tree...");
exit(0);
}

if(delp->parent->lchild==delp) delp->parent->lchild=0;
if(delp->parent->rchild==delp) delp->parent->rchild=0;

Destroy(delp);

return 2;
}

int Destroy(TreeNode *root) //销毁二叉树
{
if(!root) return 0;

Destroy(root->lchild);
Destroy(root->rchild);
free(root);

printf("Destroy the tree...");
exit(0);
}本回答被提问者和网友采纳