void Red_Black_Tree::rb_delete(Node* z) { Node *y = z; Node *x; int y_original_color = y->color; if (z->left == _NIL) { x = z->right; rb_transplant(z, z->right); } else if (z->right == _NIL) { x = z->left; rb_transplant(z, z->left); } else { y = minimum(z->right); y_original_color = y->color; x = y->right; if (y->parent == z) x->parent = y; else { rb_transplant(y, y->right); y->right = z->right; y->right->parent = y; } rb_transplant(z, y); y->left = z->left; y->left->parent = y; y->color = z->color; } if (y_original_color == 0) rb_delete_fixup(x); }
void rb_delete(rbt *T, rbn *z) { rbn *x, *y = z; COLOR y_original_color = y->color; if (z->left == T->nil) { x = z->right; rb_transplant(T, z, z->right); } else if (z->right == T->nil) { x = z->left; rb_transplant(T, z, z->left); } else { y = rb_minimum(T, z->right); y_original_color = y->color; x = y->right; if (y->p == z) x->p = y; else { rb_transplant(T, y, y->right); y->right = z->right; y->right->p = y; } rb_transplant(T, z, y); y->left = z->left; y->left->p = y; y->color = z->color; } if (y_original_color == BLACK) rb_delete_fixup(T, x); }
void rb_delete(RB_TREE *T, RB_NODE *z) { RB_NODE *x, *y; int y_orginal_color; y = z; y_orginal_color = y->color; if (z->left == T->nil) { x = z->right; rb_transplant(T, z, z->right); } else if(z->right == T->nil) { x = z->left; rb_transplant(T, z, z->left); } else { y = rbtree_minimum(T, z->right); y_orginal_color = y->color; x = y->right; if (y->parent == z) x->parent = y; else { rb_transplant(T, y, y->right); y->right = z->right; y->right->parent = y; } rb_transplant(T, z, y); y->left = z->left; y->left->parent = y; y->color = z->color; } if (y_orginal_color == BLACK) rb_delete_fixup(T, x); }
void k_rbtree_delete(k_rbtree_t* t,k_rbnode_t* z) { /* y's postion is the really to be delete, * move y to z's position and move x to y's postion */ k_rbnode_t* y = z; k_rbnode_t* x = t->nil_node; enum k_color_type_t y_old_color = y->color; if(z->left == t->nil_node){//if one of z's child is nil move the other child to z; x = z->right; rb_transplant(t,z,z->right); }else if(z->right == t->nil_node){ x = z->left; rb_transplant(t,z,z->left); }else{// y to be z's successor y = rb_minimum(t,z->right); y_old_color = y->color; x = y->right; //since y has no left child then move y's right to be y if(y->parent == z){//move x to y's postion x->parent = z; }else{ rb_transplant(t,y,x); y->right = z->right; y->right->parent = y; } // move y to z's postion rb_transplant(t,z,y); y->left = z->left; y->left->parent = y; y->color = z->color; } if(y_old_color == k_color_black){ k_rbtree_delete_fixup(t,x); } }
/* delete node n from red-black tree rooted at root */ static struct rb_node *rb_delete_node(struct rb_node **root, struct rb_node *n) { struct rb_node *t; struct rb_node *new; char old_color; /* nothing to do */ if (n == NIL) return *root; t = n; old_color = t->c; if (n->lc == NIL) { /* right child or no child */ new = n->rc; rb_transplant(root, n, n->rc); }