Browse Source

Merge branch 'tree_alloc' of gitea:cameron/cs241-project into tree_alloc

tree_alloc
Thomas Johnson 1 year ago
parent
commit
b643cf56b2
  1. 10
      tree_alloc.c

10
tree_alloc.c

@ -188,7 +188,7 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
if (sibling->left->color == COLOR_BLACK && sibling->right->color == COLOR_BLACK) {
node->color = COLOR_BLACK;
sibling->color = COLOR_RED;
repair_after_remove(root_ptr, parent);
repair_after_remove(root_ptr, node->parent);
} else {
if (node->parent->left == node && sibling->right->color == COLOR_BLACK) {
rotate_right(root_ptr, sibling);
@ -196,7 +196,7 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
sibling->color = COLOR_RED;
sibling->right->color = COLOR_RED;
rotate_left(root_ptr, parent);
rotate_left(root_ptr, node->parent);
node->color = get_sibling(node->parent)->color = COLOR_BLACK;
} else if (node->parent->right == node && sibling->left->color == COLOR_BLACK) {
rotate_left(root_ptr, sibling);
@ -220,17 +220,17 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) {
TreeAlloc *parent = node->parent;
if (!node->left) {
replace = node->right;
do_fix = node->color == COLOR_BLACK;
do_repair = node->color == COLOR_BLACK;
replace_node(root_ptr, node, replace);
} else if (!node->right) {
replace = node->left;
do_fix = node->color == COLOR_BLACK;
do_repair = node->color == COLOR_BLACK;
replace_node(root_ptr, node, replace);
} else {
TreeAlloc *tmp = node->right;
while (tmp->left) tmp = tmp->left;
replace = tmp->right;
do_fix = tmp == COLOR_BLACK;
do_repair = tmp->color == COLOR_BLACK;
if (tmp != node->right) {
replace_node(root_ptr, tmp, replace);
tmp->right = node->right;

Loading…
Cancel
Save