简体   繁体   中英

need Delete operation of BST for my program

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.

您可以将data字段,因为它是去除leftright的引用以及其他引用该点要删除应该足够的对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM