title: Delete node in binary search tree
body: <p>I have implemented the following methods for deleting a node in a BST for following the example that is posted <a href="https://www.geeksforgeeks.org/binary-search-tree-set-2-delete/" rel="nofollow noreferrer">here</a>:</p>
  
  <p><strong>class NodeT</strong></p>
  
  <pre><code>public class NodeT {
      int elem;
      NodeT left;
      NodeT right;
      public NodeT(int elem){
          this.elem=elem;
      }
  }
  </code></pre>
  
  <p><strong>class BinaryTree</strong></p>
  
  <pre><code>public class BinaryTree {
      NodoT root;
      public void insertElem(int n){
          root=addRec(root,n);
      }
      public NodoT addRec(NodeT n, int elem){
          if (n==null){
              n=new NodeT(elem);
          }
          else{
              if (elem&lt;n.elem){
                  n.left=addRec(n.left,elem);
              }
              else{
                  n.right=addRec(n.right,elem);
              }
          }
          return n;
      }
      public void inorder(NodeT n){
          if (n!=null){
              inorder(n.left);
              System.out.println(n.elem);
              inorden(n.right);
          }
      }
  
      public NodeT search(NodeT root, int n){
          if (root.elem==n) return root;
          else{
              if (n&lt;root.elem){
                  if (root.left!=null){
                      return search(root.left,n);
                  }
                  else return null;
              }
              else{
                  if (root.right!=null){
                      return search(root.right,n);
                  }
                  else return null;
              }
          }
      }
  
      public void delete(int n){
         root=deleteNode(root,n);
      }
  
  
      public NodeT deleteNode(NodeT curr, int n){
          NodoT answ;
          answ=search(curr,n);
          if (answ==null){
              System.out.println("not found");
              return curr;
          }
          else{
  
              if (curr.left==null)return curr.right; 
              else if (curr.right==null) return curr.left;
              curr.elem=minValue(curr.right);
              curr.right=deleteNode(curr.right,curr.elem);
          }
          return curr;
      }
  
  
      int minValue(NodoT curr){
  
          int min=curr.elem;
          while (curr.left!=null){
              menor=curr.left.elem;
              curr=curr.left;
          }
          return min;
      }
  
  
  //main program
  
  
  BinaryTree bt=new BinaryTree();        
     int data[]={50,30,70,20,40,60,80};
  
      for (int i=0;i&lt;data.length;i++){
          bt.insertElem(data[i]);
      }
      bt.inorder(bt.root);
  
      bt.delete(20);
      bt.inorder(bt.root);
  
  
      bt.delete(30);
      bt.inorder(bt.root);
  
  
      bt.delete(50);
      bt.inorder(bt.root);
  </code></pre>
  
  <p>However, when I tested,  it prints "not found" on line <code>bt.delete(50);</code>, what am I doing wrong? </p>