Guest User

Untitled

a guest
Apr 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. void Delete(T, K)
  2. {
  3.     if (T == null) return; // K not found so nothing to do
  4.     if (T.root == K)
  5.     {
  6.         if (T.left <> null)
  7.         {
  8.             BinaryTree max = findMax(T.left);
  9.             T.root = max.root;
  10.             Delete(T.left, max.root);
  11.         }
  12.         else if (T.right <> null)
  13.         {
  14.         BinaryTree min = findMin(T.right);
  15.         T.root = min.root;
  16.         Delete(T.right, min.root);
  17.         }
  18.         else
  19.         {
  20.         Free(T);
  21.         }
  22.     } // T is a leaf so free its memory allocation (e.g., T.root = null)
  23.     else if (T.root < K)
  24.     {
  25.         Delete(T.right, K);
  26.     }
  27.     else if (T.root > K)
  28.     {
  29.         Delete(T.left, K);
  30.     }
  31.     cleanUp(T); // remove any leaf nodes where T.root = null
  32. }
Add Comment
Please, Sign In to add comment