Example #1
0
struct node *delete_node(struct node *root) {
    struct node *child, *aux;
    unsigned int key;
    if (root->left == NULL) {
        aux = root->right;
        free(root);
        return aux;
    } else if (root->right == NULL) {
        aux = root->left;
        free(root);
        return aux;
    } else {

        if (root->right->left == NULL) {
            child = root->right;
            root->value = child->value;
            root->key = child->key;
            root->right = child->right;
            free(child);
        } else {
            key = root->key;
            child = node_min(root->right);
            root->value = child->value;
            root->key = child->key;
            child->key = key;
            delete_rec(root, key);
        }
        
        set_height(root);
        return rebalance(root);
    }
}
Example #2
0
int
hb_itor_first(hb_itor *itor)
{
	hb_tree *t;

	ASSERT(itor != NULL);

	t = itor->tree;
	itor->node = t->root ? node_min(t->root) : NULL;
	RETVALID(itor);
}
Example #3
0
int
wb_itor_first(wb_itor *itor)
{
	ASSERT(itor != NULL);

	if (itor->tree->root == NULL)
		itor->node = NULL;
	else
		itor->node = node_min(itor->tree->root);
	RETVALID(itor);
}
Example #4
0
void
hb_tree_walk(hb_tree *tree, dict_vis_func visit)
{
	hb_node *node;

	ASSERT(tree != NULL);

	if (tree->root == NULL)
		return;
	for (node = node_min(tree->root); node; node = node_next(node))
		if (visit(node->key, node->dat) == 0)
			break;
}
Example #5
0
struct node *node_min(struct node *root) {
    return (root->left == NULL)? root : node_min(root->left);
}