Question: I have java code for an AVL Tree Map, but I cannot figure out how to do the balance() function (the place where this needs
I have java code for an AVL Tree Map, but I cannot figure out how to do the balance() function (the place where this needs to be filled out is marked by //Fix). No other accomidating functions should be needed in this code.
\\AVLTreeMap.java public class AVLTreeMap implements Map { class Node { String key; String value; int height; Node parent; Node left; Node right; public Node(String key, String value) { this.key = key; this.value = value; this.height = 1; this.parent = null; this.left = null; this.right = null; } public int balance() { \\Fix return -1; } } private int size; private Node root; public AVLTreeMap() { root = null; size = 0; } public int size() { size = 0; Node node = root; while (node != null) { size++; node = node.right; } return size; } public void put(String key, String value) { if (key == null || value == null) { throw new IllegalArgumentException("Key or value is null"); } if (root == null) { root = new Node(key, value); size = 1; root.parent = root; } else { Node node = new Node(key, value); node.parent = root; node.right = null; node.left = null; root.right = node; size++; } } public String get(String key) { Node node = root.parent; while (node != null) { if (node.key.equals(key)) { return node.value; } node = node.right; } return null; } \\Map.java
public interface Map { public int size(); public void put(String key, String value); public String get(String key); } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
