This method is part of the Binary Search Tree implementation. Question: Replace
ID: 3729521 • Letter: T
Question
This method is part of the Binary Search Tree implementation. Question: Replace the put(K key, V value) method with a recursive method – i.e. one that doesn’t use a loop. public void put(K key, V value) { if (root == null) { TreeNode node = new TreeNode(key, value); this.root = node; } else { TreeNode current = root; while (current != null) { int c = key.compareTo(current.key); // key == current.key if (c == 0) { current.value = value; return; } // key < current.key else if (c < 0) { if (current.left != null) { current = current.left; } else { TreeNode node = new TreeNode(key, value); current.left = node; } } //c > 0, i.e. key > current.key else { if (current.right != null) { current = current.right; } else { TreeNode node = new TreeNode(key, value); current.right = node; } } } } }