c_avl_node_t *y;
c_avl_node_t *b;
+ assert (x != NULL);
+ assert (x->left != NULL);
+
p = x->parent;
y = x->left;
b = y->right;
y->height = calc_height (y);
return (y);
-} /* void rotate_left */
+} /* void rotate_right */
/*
* (x) (y)
c_avl_node_t *y;
c_avl_node_t *b;
+ assert (x != NULL);
+ assert (x->right != NULL);
+
p = x->parent;
y = x->right;
b = y->left;
{
new->parent = NULL;
t->root = new;
+ t->size = 1;
return (0);
}
n = t->root;
while ((n->left != NULL) || (n->right != NULL))
{
- int height_left = (n->left == NULL) ? 0 : n->left->height;
- int height_right = (n->right == NULL) ? 0 : n->right->height;
+ if (n->left == NULL)
+ {
+ n = n->right;
+ continue;
+ }
+ else if (n->right == NULL)
+ {
+ n = n->left;
+ continue;
+ }
- if (height_left > height_right)
+ if (n->left->height > n->right->height)
n = n->left;
else
n = n->right;
*value = n->value;
free_node (n);
+ --t->size;
rebalance (t, p);
return (0);