From 2b099142e3d466f09229e2fd6405e062b4a73455 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 24 Jan 2023 21:35:32 +0000 Subject: [PATCH] sandbox: btree: fix replace_node_with_one_subtree() not updating tree root --- sandbox/btree/btree.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sandbox/btree/btree.c b/sandbox/btree/btree.c index 3526a77..c36c211 100644 --- a/sandbox/btree/btree.c +++ b/sandbox/btree/btree.c @@ -243,10 +243,6 @@ static void delete_fixup(btree_t *tree, btree_node_t *w) z = z->b_parent; nr_rotations++; - - if (nr_rotations > 10) { - assert(0 && "too many rotations"); - } } } @@ -338,7 +334,9 @@ static btree_node_t *replace_node_with_one_subtree(btree_t *tree, btree_node_t * } btree_node_t *w = z; - if (IS_LEFT_CHILD(p, node)) { + if (!p) { + tree->b_root = z; + } else if (IS_LEFT_CHILD(p, node)) { p->b_left = z; } else if (IS_RIGHT_CHILD(p, node)) { p->b_right = z;