删除叶结点,C语言!

来源:百度知道 编辑:UC知道 时间:2024/05/15 19:41:57
已知二叉树采用二叉链表的存储结构,根结点的地址为T,删去并释放数据值为key的叶结点。

请问这个算法怎么写??谢谢,是C语言滴!

中序遍历:
void inorder(Tree* root, Tree* top , bool left)
{
if (root.value == key)
{
if (left)
top.left = NULL;
else
top.right = NULL; //delete the node
}
inorder(root.lchild, root, true);
inorder(root.rchild, root, flase);
}

先寻找点,然后在判断,如果他的左子数为空右子数不为空,需要保存他的上一级节点在把右子树接上去,左子树右子树都为空的情况下直接删除改节点