The following code is provided for the Node class and the ad…
The following code is provided for the Node class and the add method of a BinarySearchTree: private static class Node { public Comparable data; public Node left; public Node right;}public void add(Comparable obj) { Node newNode = new Node(); newNode.data = obj; newNode.left = null; newNode.right = null; // Only one null check root = addNode(root, newNode);} Write the Java code for the following static method in the BinarySearchTree class: private static Node addNode(Node parent, Node newNode){ //Base case insert code here //Recursive code: go left to right } Your method should work as follows: If parent is null, return newNode. Otherwise, compare newNode.data with parent.data: If newNode.data is smaller, recursively add it to the left subtree. Otherwise, recursively add it to the right subtree. Return parent after insertion. Requirements: Use recursion. Do not modify the provided Node class or add method. Assume the tree does not contain duplicate values.
Read Details