title: How to implement the delete method for BinarySearchTree?
body: <p>This is my code. I am stuck on the delete part. The insert and get methods are all fine. I want to save the old tree so that I can link the node together soon.</p>
  
  <pre><code>private BinaryTree&lt;K, V&gt; left, right;
  public BinaryTree(K key, V value) {
      // Leaf node constructor
      this.key = key;
      this.value = value;
  }
  
  public V put(K key, V value) {
      if (this.key.equals(key)) {
          // Replacing the value at the current node
          V ret = this.value;
          this.value = value;
          return ret;
      }
      int comp = this.key.compareTo(key);
      if (comp &lt; 0) {
          // this.key &lt; key
          // Put the key we are inserting to the right
          // of the current key
          if (right == null) {
              // We have to create a node to the right
              // (Leaf node)
              right = new BinaryTree&lt;K, V&gt;(key, value);
              return null; // Per interface
          }
          return right.put(key, value);
      } else {
          // We don't support keys where equals and compareTo
          // disagree with each other.
          assert(comp != 0);
          // At this point, we know that comp &gt; 0
          // Therefore, this.key &gt; key
          // Put the key we are inserting to the left of current
          if (left == null) {
              // We have to create a node to the left
              // (Leaf node)
              left = new BinaryTree&lt;K, V&gt;(key, value);
              return null; // Per interface
          }
          return left.put(key, value);
          // Exercise: You could write a tiny little private method
          // to implement this redundant code in one place.
      }
  }
  
  public V get(K key) {
      int comp = this.key.compareTo(key);
      if (comp &lt; 0) {
          // this.key &lt; key
          // Recurse to the right
          if (right == null) {
              // Not in the tree
              return null;
          }
          return right.get(key);
      } else if (comp &gt; 0) {
          // this.key &gt; key
          // Recurse to the left
          if (left == null) {
              // Not in the tree
              return null;
          }
          return left.get(key);           
      } else {
          assert(this.key.equals(key));
          return value;
      }
  }
  
  public boolean containsKey(K key) {
      // Note: Doesn't work with null values!
      return get(key) != null;
  }
  
  public BinaryTree&lt;K, V&gt; delete(K key) {
      BinaryTree&lt;K,V&gt; tmp,childL,childR,OldTree;
      int comp=this.key.compareTo(key);
      if(comp&lt;0){
          //this.key&lt;Key goes right
          if(this.right==null){
              throw new UnsupportedOperationException("Nothing you can delete here");
  
          }
          else{
  
              return this.right.delete(key);
  
                  }
  
          }
      if(comp&gt;0){
          if(this.left==null){
              throw new UnsupportedOperationException("Nothing you can delte here");
          }
          else{
              return this.left.delete(key);
          }
                  }
      if(this.key.equals(key)){
  
  
      }
          {
  
  
          }
      //}
      // IMPLEMENT THIS FOR YOUR ASSIGNMENT!
      // Remove key from the tree, if it exists.
      // Throw UnsupportedOperationException if key isn't in the tree.
      // Return the new root node if we did delete the key.
      // (The new root node may be the same as the old one.)
      // If you deleted the last node in the tree, it will return null.
          return null;
  
  }}
  </code></pre>
  
  <p>Some details are posted on the common, is it logical error on my code?</p>