Binary Search Tree : Insertion

  • + 0 comments
    public static Node insert(Node root,int data) {
            root = addRecursive(root, data);
            return root;
        }
        
        public static Node addRecursive(Node current, int data) {
            if(current == null) return new Node(data);
            else {
                if(current.data < data) {
                    current.right = addRecursive(current.right, data);
                }
                if(current.data > data) {
                    current.left = addRecursive(current.left, data);
                }
            }
            return current;
        }