红黑树调试通过

This commit is contained in:
建峰 2024-07-02 15:03:57 +08:00
parent 71ba5642ae
commit 590a50d9e7
2 changed files with 7 additions and 3 deletions

View File

@ -1339,7 +1339,7 @@ bool tree_rb_delete_fix(struct _tree* self, struct _tree_node* node)
}
else
{
if(father->color = RBT_BLACK)
if(father->color == RBT_BLACK)
{
// case 4
// father is black, brother has no children
@ -1388,7 +1388,7 @@ bool tree_rb_delete_fix(struct _tree* self, struct _tree_node* node)
}
else
{
if(father->color = RBT_BLACK)
if(father->color == RBT_BLACK)
{
// case4
brother->color = RBT_RED;
@ -1406,7 +1406,7 @@ bool tree_rb_delete_fix(struct _tree* self, struct _tree_node* node)
if(tmp != NULL && tmp->parent == NULL)
{
self->_root = node;
self->_root = tmp;
}
}

View File

@ -155,6 +155,10 @@ static bool tree_rb_check_color(struct _tree *self, struct _tree_node* root, int
static bool tree_rb_check(struct _tree* self)
{
assert(self != NULL);
if(self->_root == NULL)
{
return true;
}
if(self->_root->color != RBT_BLACK)
{