Advertisement
snowywhitee

Untitled

Dec 7th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. void del(node *peak)
  2. {
  3.     if (peak->l == NULL && peak->r == NULL)
  4.     {
  5.         if (peak->prev != NULL && peak->prev->key > peak->key)
  6.         {
  7.             peak->prev->l = NULL;
  8.         } else if (peak->prev != NULL && peak->prev->key < peak->key)
  9.         {
  10.             peak->prev->r = NULL;
  11.         }
  12.         free(peak);
  13.         peak = NULL;
  14.         return;
  15.     }
  16.     if (peak->r == NULL)
  17.     {
  18.         if (peak->prev != NULL && peak->prev->key > peak->key)
  19.         {
  20.             peak->prev->l = peak->l;
  21.         } else if (peak->prev != NULL && peak->prev->key < peak->key)
  22.         {
  23.             peak->prev->r = peak->l;
  24.         }
  25.         free(peak);
  26.         return;
  27.     }
  28.     node *cur = peak->r;
  29.     while (cur->l != NULL)
  30.     {
  31.         cur = cur->l;
  32.     }
  33.     peak->key = cur->key;
  34.     del(cur);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement