summaryrefslogtreecommitdiff
path: root/src/03/rb_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/03/rb_tree.c')
-rw-r--r--src/03/rb_tree.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/03/rb_tree.c b/src/03/rb_tree.c
index cb576b4..1b74d90 100644
--- a/src/03/rb_tree.c
+++ b/src/03/rb_tree.c
@@ -90,7 +90,9 @@ static void repair_from(RBTree *tree) {
if (pibling && pibling->colour == red) {
parent->colour = black;
pibling->colour = black;
- grand_parent_of(tree)->colour = red;
+ RBTree *grand_parent = grand_parent_of(tree);
+ if (grand_parent->parent)
+ grand_parent->colour = red;
repair_from(grand_parent_of(tree));
} else {
RBTree *grand_parent = grand_parent_of(tree);
@@ -114,7 +116,8 @@ static void repair_from(RBTree *tree) {
rb_rotate_left(grand_parent);
}
parent->colour = black;
- grand_parent->colour = red;
+ if (grand_parent->parent)
+ grand_parent->colour = red;
}
}