Question: Examine the following code to add a node to BST. Logic is correct, but the tree is empty (never being able to insert a node).
Examine the following code to add a node to BST. Logic is correct, but the tree is empty (never being able to insert a node). Explain why the following code is not working in your own words. public class SearchTree { private IntTreeNode overall Root; // Adds the given value to this BST in sorted order. 11 (THIS CODE DOES NOT WORK PROPERLY!) public void add(int value) { addCoverall Root, value); } private void add(IntTreeNode node, int value) { if (node == null) { node = new IntTreeNode(value); } else if (value node.data) { add(node.right, value); } // else a duplicate (don't add) }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
