Question
SOLVE IN JAVA!!! BST.java import java.util.ArrayList; /** BST implementation for Dictionary ADT */ class BST , E> implements Dictionary { private BSTNode root; // Root
SOLVE IN JAVA!!!
BST.java
import java.util.ArrayList;
/** BST implementation for Dictionary ADT */ class BST
/** Constructor */ BST() { root = null; nodecount = 0; }
/** Reinitialize tree */ public void clear() { root = null; nodecount = 0; }
/** * Insert a record into the tree. * * @param k * Key value of the record. * @param e * The record to insert. */ public void insert(K k, E e) { root = inserthelp(root, k, e); nodecount++; }
/** * Remove a record from the tree. * * @param k * Key value of record to remove. * @return Record removed, or null if there is none. */ public E remove(K k) { E temp = findhelp(root, k); // find it if (temp != null) { root = removehelp(root, k); // remove it // System.out.println("called removehelp"); nodecount--; } return temp; }
/** * Remove/return root node from dictionary. * * @return The record removed, null if empty. */ public E removeAny() { if (root == null) return null; E temp = root.element(); root = removehelp(root, root.key()); --nodecount; return temp; }
/** * @return Record with key k, null if none. * @param k * The key value to find. */ public E find(K k) { return findhelp(root, k); }
/** @return Number of records in dictionary. */ public int size() { return nodecount; }
private E findhelp(BSTNode
private BSTNode
private BSTNode
private BSTNode
else { rt.setLeft(deletemin(rt.left())); return rt; } }
/** * Remove a node with key value k * * @return The tree with the node removed */ private BSTNode
/** * Creates a list storing the the nodes in the subtree of a node, ordered * according to the inorder traversal of the subtree. */
protected void inorderElements(BSTNode
/** Returns an iterable collection of the tree nodes. */ public Iterable
public Iterable
protected void findAllhelp(BSTNode
/* the following are for solving the exercises in Shaffer, ch. 5 */
public Iterable
protected void rangehelp(BSTNode
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