Question

Following BST ADT signatrue should be provided:
    new: make a new empty tree
    i: insert a string (get the value from the user)
    r: remove a node contaning a string (remove it from the tree)
    c: contains a string (return and report a boolean indicating success)
    g: get a node that has a string as value
    x: findMax, returns a string
    n: findMin, returns a string
    v: val, gets the value stored in the root node
    s: size
    e: empty
    q: quit the tester loop
    p: print the tree for inspection (see below)

To print a tree, print a recursive method, and make it traverse the tree using one of two traversal orders (your choice). Examples of each are shown below for a small binary search tree.

example: reverse in-order:
weathervane
stovepipe
pattern
machine
jackstand
garage
airplane

example: pre-order
machine
    garage
       airplane
       jackstand
   stovepipe
       pattern
       weathervane

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Node<T>{
       T data;
       Node<T> left, right, parent;

       public Node (T data, Node<T> l, Node<T> r, Node<T> p){
                left = l;
                right = r;
                parent = p;
                this.data = data;
       }
       public Node (T data, Node<T> p){
                this(data, null, null, p);
       }      
    }
   
    private Node<T> root;
    private int size;
   
    public BST() {
       root = null;
       size = 0;
    }
      
   
    public void insert(T data){
       if (root == null) {
            root = new Node<T>(data, null);
       } else{
            insert(root, data);
       }      
    }
   
    private void insert(Node<T> node, T data){
       int comparison = node.data.compareTo( data ) ;
       if ( comparison > 0 ) {
            if (node.left == null) {
                node.left = new Node<T>(data, node);
                size++;
            } else {
                insert(node.left, data);
            }
       } else if ( comparison < 0 ) {
            if (node.right == null) {
                node.right = new Node<T>(data, node);
                size++;
            } else {
                insert(node.right, data);
            }
       }
    }...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Land Tract Problems in Java
Homework Solution
$5.00
Computer Science
Java Programming
Land Tract
Methods
Strings
Area
Equality
Size
Dimensions
Statements
Variables
Hangman Application in Java
Homework Solution
$20.00
Computer Science
Java Programming
Hangman
Applications
Classes
Attributes
Strings
Users
Guesses
Players
Methods
Constructors
Loops
Getters
Setters
Characters
The CIS Car Dealership Application in Java
Homework Solution
$60.00
Computer Science
Java Programming
OOP
Arrays
Classes
Program Classes
Car Dealership
Inventory
Objects
System Console
Commands List
User Dialog
Strings
Java Lists
Homework Solution
$50.00
Computer Science
Java Programming
Lists
Largest Elements
Smallest Elements
Range
Comparisons
Brute-Force
Algorithms
Integers
Invoice Application in Java
Homework Solution
$60.00
Computer Science
Java Programming
OOP Design
Invoice Application
Array Lists
Items
Objects
Orders
Data
Inventory Database
Prices
Quantity
Integers
Methods
Java Problems With Polynomials
Homework Solution
$58.00
Computer Science
Java Programming
Polynomials
Coefficients
Terms
Collections
Constructors
Interfaces
Linked Lists
Objects
Get help from a qualified tutor
Live Chats