Guest User

Untitled

a guest
Jan 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. node* del(node* root,int val)
  2. {
  3.     if(root)
  4.     {
  5.         if(root->val==val)
  6.         {
  7.             if(!root->lft && !root->ryt)
  8.             return NULL;
  9.             else if(!root->lft)
  10.             {
  11.                 root->ryt->parent=root->parent;
  12.                 return root->ryt;
  13.             }
  14.             else if(!root->ryt)
  15.             {
  16.                 root->lft->parent=root->parent;
  17.                 return root->lft;
  18.             }
  19.             root->val=findMax(root->lft);
  20.             root->lft=del(root->lft,root->val);
  21.         }
  22.         else if(root->val > val)
  23.         root->lft=del(root->lft,val);
  24.         else
  25.         root->ryt=del(root->ryt,val);
  26.     }
  27.     return root;
  28. }
Add Comment
Please, Sign In to add comment