How to recursively remove nodes in a binary tree?

0

I can not understand and code the operation of the method of removing nodes, in a binary tree.

Note: The methods for adding and printing (RED) have already been implemented.

package trees;

public class binaryTree {

    Node root;

    public void add(char value){
        addNode(root, value);
    }

    public void addNode(Node node, char value){

        if (root == null){
            root = new Node(value);
        }else{
            if (value < node.getValue()){
                if (node.getLeft() != null){
                    addNode(node.getLeft(), value);
                }else {
                    node.setLeft(new Node(value));
                }
            }else{
                if (value > node.getValue()){
                    if (node.getRight() != null){
                        addNode(node.getRight(), value);
                    }else{
                        node.setRight(new Node(value));
                    }
                }

            }

        }

    }

    public void printTreeRED(){
        print(root);
    }

    private void print(Node node){
        if (node != null){
            System.out.println(node.getValue() + " ");
            print(node.getLeft());
            print(node.getRight());
        }
    }
    
asked by anonymous 27.04.2018 / 04:26

0 answers