Browse Source

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

Thomas Johnson 5 months ago
parent
commit
b643cf56b2
1 changed files with 5 additions and 5 deletions
  1. 5
    5
      tree_alloc.c

+ 5
- 5
tree_alloc.c View File

@@ -188,7 +188,7 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
188 188
 		if (sibling->left->color == COLOR_BLACK && sibling->right->color == COLOR_BLACK) {
189 189
 			node->color = COLOR_BLACK;
190 190
 			sibling->color = COLOR_RED;
191
-			repair_after_remove(root_ptr, parent);
191
+			repair_after_remove(root_ptr, node->parent);
192 192
 		} else {
193 193
 			if (node->parent->left == node && sibling->right->color == COLOR_BLACK) {
194 194
 				rotate_right(root_ptr, sibling);
@@ -196,7 +196,7 @@ void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) {
196 196
 				sibling->color = COLOR_RED;
197 197
 				sibling->right->color = COLOR_RED;
198 198
 
199
-				rotate_left(root_ptr, parent);
199
+				rotate_left(root_ptr, node->parent);
200 200
 				node->color = get_sibling(node->parent)->color = COLOR_BLACK;
201 201
 			} else if (node->parent->right == node && sibling->left->color == COLOR_BLACK) {
202 202
 				rotate_left(root_ptr, sibling);
@@ -220,17 +220,17 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) {
220 220
 	TreeAlloc *parent = node->parent;
221 221
 	if (!node->left) {
222 222
 		replace = node->right;
223
-		do_fix = node->color == COLOR_BLACK;
223
+		do_repair = node->color == COLOR_BLACK;
224 224
 		replace_node(root_ptr, node, replace);
225 225
 	} else if (!node->right) {
226 226
 		replace = node->left;
227
-		do_fix = node->color == COLOR_BLACK;
227
+		do_repair = node->color == COLOR_BLACK;
228 228
 		replace_node(root_ptr, node, replace);
229 229
 	} else {
230 230
 		TreeAlloc *tmp = node->right;
231 231
 		while (tmp->left) tmp = tmp->left;
232 232
 		replace = tmp->right;
233
-		do_fix = tmp == COLOR_BLACK;
233
+		do_repair = tmp->color == COLOR_BLACK;
234 234
 		if (tmp != node->right) {
235 235
 			replace_node(root_ptr, tmp, replace);
236 236
 			tmp->right = node->right;

Loading…
Cancel
Save