Question: Create an AVL Tree Map. That is, create an AVLTree which implements a Map interface. The file which needs to be worked on is AVLTreeMap.java

Create an AVL Tree Map. That is, create an AVLTree which implements a Map interface. The file which needs to be worked on is AVLTreeMap.java (the functions which need to be filled out are marked by \\FIX). I have included all relevant files which are: Main.java (runs a test case), Map.java (the map interface) and AVLTreeMap.java (the file which needs to be worked on).

\\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() { // FIX }

public int size() { // FIX return -1; }

public void put(String key, String value) { // FIX }

public String get(String key) { // FIX return null; }

public void print() { this.print(this.root, "", 0); }

\\Map.java

public interface Map { public int size(); public void put(String key, String value); public String get(String key); }

\\Main.java

public class Main { public static void main(String[] args) { Map map = new AVLTreeMap(); map.put("dog", "a domesticated canid"); map.put("cat", "a small domesticated carnivore"); System.out.println(map.size()); // 2 System.out.println(map.get("dog")); // "a domesticated canid" } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!