diff --git a/src/tree/delete.c b/src/tree/delete.c index 2a5bf61..77ad384 100644 --- a/src/tree/delete.c +++ b/src/tree/delete.c @@ -123,11 +123,15 @@ TR_treeDelete(TR_Tree * this, const void * search, TR_TreeComp comp) } else { TR_TREE_ROTATE(right, this, node->parent); } - } else { - // case 3/4 - if (NULL != sibling + sibling = TR_TREE_SIBLING(node); + } + + if (NULL == sibling + || (rbBlack == sibling->color && TR_TREE_NODE_BLACK(sibling->left) - && TR_TREE_NODE_BLACK(sibling->right)) { + && TR_TREE_NODE_BLACK(sibling->right))) { + // case 3/4 + if (NULL != sibling) { sibling->color = rbRed; } @@ -163,6 +167,7 @@ TR_treeDelete(TR_Tree * this, const void * search, TR_TreeComp comp) TR_TREE_ROTATE(left, this, sibling); } + sibling = TR_TREE_SIBLING(node); } // case 6