QuestionQuestion

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 PreviewSolution 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);
            }
       }
    }...
$35.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats