Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. int del(node *&root, node* x)
  2. {
  3.     node *p, *w;
  4.     int k = x->val;
  5.     if ((!x->left) || (!x->right))
  6.         p = x;
  7.         else
  8.             p = next(x);
  9.         if (p->left)
  10.             w = p->left;
  11.         else
  12.             w = p->right;
  13.         if (w)
  14.             w->up = p->up;
  15.  
  16.         if (!p->up) root = w;
  17.         else if (p == p->up->left) p->up->left = w;
  18.         else p->up->right = w;
  19.         if (p != x) x->val = p->val;
  20.  
  21.         delete p;
  22.         return k;
  23. }
  24.  
  25.  
  26. void modify(node*& root_1, node*& root_2, node *x_2, int cond)
  27. {
  28.     if (x_2->val == cond)
  29.     {
  30.         add(root_1, del(root_2, next(x_2)));
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement