SHARE
TWEET

lab10 function 10

a guest Nov 15th, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template <class T, class Compare>
  2. typename BST<T, Compare>::Node* BST<T, Compare>::del(BST<T, Compare>::Node *r, T data)
  3. {
  4.     if(r == nullptr)
  5.     {
  6.         return r;
  7.     }
  8.  
  9.     if(cmt(data, r->data))
  10.     {
  11.         r->left = del(r->left, data);
  12.     }
  13.     else if(cmt(r->data, data))
  14.     {
  15.         r->right = del(r->right, data);
  16.     }
  17.     else if(r->left != nullptr && r->right != nullptr)
  18.     {
  19.         r->data = minimum(r->right)->data;
  20.         r->right = del(r->right, r->data);
  21.     }
  22.     else
  23.     {
  24.         if(r->left != nullptr)
  25.         {
  26.             if(r == root)
  27.             {
  28.                 root = r->left;
  29.                 root->parent = nullptr;
  30.             }
  31.             count--;
  32.             r->left->parent = r->parent;
  33.             auto r1 = r->left;
  34.             delete r;
  35.             r = r1;
  36.         }
  37.         else
  38.         {
  39.             if(r == root)
  40.             {
  41.                 root = r->right;
  42.                 if(root != nullptr)
  43.                 {
  44.                     root->parent = nullptr;
  45.                 }
  46.             }
  47.             count--;
  48.             if(r->right != nullptr)
  49.             {
  50.                 r->right->parent = r->parent;
  51.             }
  52.             auro r2 = r->rigth;
  53.             delete r;
  54.             r = r2;
  55.         }
  56.     }
  57.     return r;
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top