Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 doesnt 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; } } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started