From e6a99b2d3d3831cf9040742d99f0a16ad44744d6 Mon Sep 17 00:00:00 2001 From: andyzhu Date: Tue, 4 Jun 2019 10:38:20 +0800 Subject: [PATCH] change 24_tree in c-cpp --- c-cpp/24_tree/binarysearchtree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/c-cpp/24_tree/binarysearchtree.c b/c-cpp/24_tree/binarysearchtree.c index c3194fd..3b2d1b3 100644 --- a/c-cpp/24_tree/binarysearchtree.c +++ b/c-cpp/24_tree/binarysearchtree.c @@ -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) { child = p->lchild; } else { child = p->rchild; } + if(pp->data>p->data) + { + pp->lchild=child; + } else + { + pp->rchild=child; + } free(p); + return TRUE; } //没有节点 - if (pp->lchild == p) { + if (pp->lchild == p) {//这里面临pp除p以外的节点为null的情况 pp->lchild = child; } else { pp->rchild = child;