java Delete a Binary Tree node containing two children
<p>This is the last case where the node to be deleted has two children. I cant figure out what I am doing wrong . Please help.</p>

<pre><code>    //BTNode has two children
    else if (u.getLeft() != null &amp;&amp; u.getRight() != null){
        //if node to delete is root
        BTNode&lt;MyEntry&lt;K,V&gt;&gt; pred = u.getRight();


        while (pred.getLeft().element() != null){
            pred = pred.getLeft();
        }


        BTNode&lt;MyEntry&lt;K,V&gt;&gt; predParent = pred.getParent();
        if (!hasRightChild(pred)){
            predParent.setLeft(new BTNode&lt;MyEntry&lt;K,V&gt;&gt;(null,predParent,null,null));}
        if (hasRightChild(pred)){
            BTNode&lt;MyEntry&lt;K,V&gt;&gt; predChild = pred.getRight();
            predParent.setLeft(predChild);
            predChild.setParent(predParent);
        }


        return returnValue;
</code></pre>

<p>ok so modify it like this ?? </p>

<pre><code>        u.setElement(succ.element());



        BTNode&lt;MyEntry&lt;K,V&gt;&gt; succParent = succ.getParent();
        if (!hasLeftChild(succ)){
            succParent.setRight(new BTNode&lt;MyEntry&lt;K,V&gt;&gt;(null,succParent,null,null));}
        if (hasLeftChild(succ)){
            BTNode&lt;MyEntry&lt;K,V&gt;&gt; predChild = succ.getLeft();
            succParent.setRight(predChild);
            predChild.setParent(succParent);
        }


        return returnValue;
</code></pre>
