Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.     if (root == NULL) // Sprawdzenie czy drzewo istnieje
  2.         return root;
  3.  
  4.     if (key > root->key)
  5.         root->right = del(root->right, key);
  6.     else
  7.         if (key < root->key)
  8.             root->left = del(root->left, key);
  9.         else // node key = key => delete node
  10.         {
  11.             if (root->left == NULL || root->right == NULL)
  12.             {
  13.                 avl* temp;
  14.  
  15.                 if (root->left != NULL)
  16.                     temp = root->left;
  17.                 else
  18.                     temp = root->right;
  19.  
  20.                 if (temp == NULL)
  21.                 {
  22.                     temp = root;
  23.                     root = NULL;
  24.                 }
  25.                 else // 1 podgałąź
  26.                     *root = *temp;
  27.                 delete temp;
  28.             }
  29.             else
  30.             {
  31.                 avl* min = root->right;
  32.                 while (min->left != NULL) //szukanie minimum
  33.                 {
  34.                     min = min->left;
  35.                 }
  36.                 root->key = min->key;
  37.                 root->right = del(root->right, min->key);
  38.             }
  39.         }
  40.  
  41.     if (root == NULL) // Sprawdzenie czy został usunięty jedyny node
  42.         return root;
  43.  
  44.     root->height = std::max(height(root->left), height(root->right)) + 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement