Skip to content

Commit e6a99b2

Browse files
committed
change 24_tree in c-cpp
1 parent 947b490 commit e6a99b2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

c-cpp/24_tree/binarysearchtree.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,26 @@ Status Delete(BTreePtr T, ElemType e) {
9595
}
9696

9797
//有一个节点
98-
if ((p->lchild != NULL) || (p->rchild != NULL)) {
98+
if ((p->lchild != NULL) || (p->rchild != NULL)) { //应该将原有的pp同child连接在一起
9999

100100
if (p->lchild) {
101101
child = p->lchild;
102102
} else {
103103
child = p->rchild;
104104
}
105+
if(pp->data>p->data)
106+
{
107+
pp->lchild=child;
108+
} else
109+
{
110+
pp->rchild=child;
111+
}
105112
free(p);
113+
return TRUE;
106114
}
107115

108116
//没有节点
109-
if (pp->lchild == p) {
117+
if (pp->lchild == p) {//这里面临pp除p以外的节点为null的情况
110118
pp->lchild = child;
111119
} else {
112120
pp->rchild = child;

0 commit comments

Comments
 (0)