change 24_tree in c-cpp

This commit is contained in:
andyzhu 2019-06-04 10:38:20 +08:00
parent 947b490d26
commit e6a99b2d3d

View File

@ -95,18 +95,26 @@ Status Delete(BTreePtr T, ElemType e) {
} }
//有一个节点 //有一个节点
if ((p->lchild != NULL) || (p->rchild != NULL)) { if ((p->lchild != NULL) || (p->rchild != NULL)) { //应该将原有的pp同child连接在一起
if (p->lchild) { if (p->lchild) {
child = p->lchild; child = p->lchild;
} else { } else {
child = p->rchild; child = p->rchild;
} }
if(pp->data>p->data)
{
pp->lchild=child;
} else
{
pp->rchild=child;
}
free(p); free(p);
return TRUE;
} }
//没有节点 //没有节点
if (pp->lchild == p) { if (pp->lchild == p) {//这里面临pp除p以外的节点为null的情况
pp->lchild = child; pp->lchild = child;
} else { } else {
pp->rchild = child; pp->rchild = child;