title: Java implementation of BST delete node
body: <p>I'm trying to make a method to delete a node in a BST and its not working..I'm using a Node class I made myself.. tried debugging but didnt get much help on addressing the error in the code.</p>
  
  <p>Appreciate any help on how to make it work.</p>
  
  <pre><code>public boolean delete(Node z)
  {
      if (z == null)
          return false;
  
      Node x,y;
      if( z.getLeft() == null || z.getRight()== null)
          y = z;
      else { 
          y = (Node) successor(z);
      }
      if (y.getLeft() != null)
          x = y.getLeft();
      else x = y.getRight();
      if(x != null)
          x.setParent(y.getParent());
      if(y.getParent() == null) {
          this.node=x;
      }
      else if (y == y.getParent().getLeft())
      {
              y.getParent().setLeft(x);
      }
          else y.getParent().setRight(x);
  
      if(y==z)
          z.setKey(y.getKey());
      return true;    
  }
  
  
  public Node treeMinimum(Node x) {
      while (x.getLeft() != null)
          x = x.getLeft();
  
      return x;
  }
  
  public Node successor(Node node) {
      Node x = node;
  
      if (x.getRight() != null)
          return treeMinimum(x.getRight());
  
      Node y = x.getParent();
      while (y != null &amp;&amp; x == y.getRight()) {
          x = y;
          y = y.getParent();
      }
  
      return y;
  }
  </code></pre>