need Delete operation of BST for my program

Viewed 26
package com.Binary_Search_Tree;

public class HackerRank 
{
    HackerRank left , right;
    int data;
    
    public HackerRank(int data)
    {
        this.data = data;
    }
    
    public void insert(int value)
    {
        if (value <= data) 
        {
            if (left == null) {
                left = new HackerRank(value);
            }else {
                left.insert(value);
            }
        }
        else 
        {
            if (right == null) {
                right = new HackerRank(value);
            }else {
                right.insert(value);
            }
        }
    }

}

In my delete operation I can go to the value but I can not make it null because its an integer value. do anyone can suggest something better which fits my code.

1 Answers

You can leave the data field as it is, removing the left and right references as well as other references that point to the object you want to delete should suffice.

Related