Esempio n. 1
0
 private BinaryNode <T> Remove(T x, BinaryNode <T> root)
 {
     if (root == null)
     {
         throw new NoNullAllowedException("Item does not exist");
     }
     if (x.CompareTo(root.getElement()) < 0)
     {
         root.setLeft(Remove(x, root.getleft()));
     }
     else if (x.CompareTo(root.getElement()) < 0)
     {
         root.setRight(Remove(x, root.getRight()));
     }
     else if (root.getleft() != null && root.getRight() != null)
     {
         root.setElement(FindMin(root.getRight()).getElement());
         root.setRight(RemoveMin(root.getRight()));
     }
     else
     {
         root = (root.getleft() != null) ? root.getleft() : root.getRight();
     }
     return(root);
 }
Esempio n. 2
0
 private BinaryNode <T> RemoveMin(BinaryNode <T> root)
 {
     if (root == null)
     {
         throw new NoNullAllowedException("Item does not exist");
     }
     else if (root.getleft() != null)
     {
         root.setLeft(RemoveMin(root.getleft()));
         return(root);
     }
     else
     {
         return(root.getRight());
     }
 }