Advertisement
patryk

Untitled

Apr 3rd, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1.  
  2. el_bst *usun(el_bst * drzewo, el_bst *x)
  3. {
  4.     el_bst *y=x->p, *z;
  5.     if((x->left) && (x->right))
  6.     {
  7.         z=(rand()%2) ? usun(root, poprzednik(x)) : usun(root, nastepnik(x));
  8.         z->left=x->left; if(z->left) z->left->p=z;
  9.         z->right=x->right; if(z->right) z->right->p=z;
  10.     }
  11.     else z=(x->left) ? x->left : x->right;
  12.  
  13.     if(z) z->p=y;
  14.     if(!y) root=z;
  15.     else if(y->left == x) y->left =z;
  16.     else y->right=z;
  17.     return x;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement