sandbox: btree_test() now checks that constructed tree is a valid AVL tree

This commit is contained in:
2023-01-21 21:42:54 +00:00
parent 09ce964190
commit cd217186a2
2 changed files with 62 additions and 4 deletions

View File

@@ -177,6 +177,7 @@ static void rotate_double_right(btree_t *tree, btree_node_t *z)
static void fix_tree(btree_t *tree, btree_node_t *w)
{
int nr_rotations = 0;
btree_node_t *z = NULL, *y = NULL, *x = NULL;
z = w;
@@ -201,13 +202,15 @@ static void fix_tree(btree_t *tree, btree_node_t *w)
update_height_to_root(z);
}
}
nr_rotations++;
next_ancestor:
x = y;
y = z;
z = z->b_parent;
}
assert(nr_rotations <= 1);
}
void btree_insert(btree_t *tree, btree_node_t *node)