Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ramo* RBTreeSuccessor(void *raiz , void* x) {
  2. tree_t *this = (tree_t*) raiz;
  3. ramo *this_2 = (ramo*) x;
  4. if (this_2->right != this->nulo) {
  5. return tree_minimum(raiz ,this_2->right);
  6. }
  7. ramo* y = this_2->parent;
  8. while (y != this_2 && x == y->right) {
  9. this_2 = y;
  10. y = y->parent;
  11. }
  12. return y;
  13. }
  14.  
  15.  
  16. void* RBTreeDelete(void* tree, void *z) {
  17. tree_t *raiz = (tree_t*) tree;
  18. ramo* this = (ramo*) z;
  19. ramo *x, *y;
  20.  
  21. if (this->left == raiz->nulo || this->right == raiz->nulo) {
  22. y = z;
  23. } else {
  24. y = RBTreeSuccessor(tree, z);
  25. }
  26.  
  27. if (y->left != raiz->nulo) {
  28. x = y->left;
  29. } else {
  30. x = y->right;
  31. }
  32.  
  33. //去掉了判断条件
  34. x->parent = y->parent;
  35.  
  36. if (y->parent == raiz->nulo) {
  37. tree = x;
  38. } else if (y == y->parent->left) {
  39. y->parent->left = x;
  40. } else {
  41. y->parent->right = x;
  42. }
  43.  
  44. if (y != z) {
  45. this->data = y->data;
  46. }
  47.  
  48. if (y->cor == BLACK) {
  49. delete_fix_up(tree, x);
  50. }
  51. return y;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement