Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Binary Search Tree - Delete Method

807591Apr 6 2008 — edited Apr 7 2008
I need help filling in the last part of this because I cannot figure out how. It is a case where the node has two kids. I replace the node with its inorder successor, and then delete its inorder successor node. Do I need to make an inOrder method?
public void delete( int myVal )
    {
        delete( root, myVal );
    }
    
private void delete( Tnode node, int value )
    {
        if ( ( node.lkid == null ) && ( node.rkid == null ) )
        {
            node = null;
        }
        else if ( ( node.lkid == null ) && ( node.rkid != null ) ) {
            node = node.rkid;
        }
        else if ( ( node.lkid != null ) && ( node.rkid == null ) ) {
            node = node.lkid;
        }
        else if ( ( node.lkid != null ) && ( node.rkid != null ) ) {
            // TODO implement
        }
    }

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 5 2008
Added on Apr 6 2008
10 comments
1,194 views