Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to write a program name BSTree.java that will: Generate 100 random integ

ID: 3761574 • Letter: Y

Question

You are to write a program name BSTree.java that will:

Generate 100 random integer numbers ranging from 1 – 99.

Store these numbers in a data structure of your choice and display the data on the screen. DO NOT SORT THIS DATA STRUCTURE.

Now build a Binary Search Tree using this set of numbers. You MUST insert the values into the tree starting from the first element of your Data Structure and go sequentially.

After building the tree, use an infix recursive method to display the data on the screen.

To build the Binary Search Tree, you must create your own Linked List.

What to turn in

Turn in BSTree.java, BStree.class OR BSTree.jar

Explanation / Answer

import java.util.*;

public class BSTree
{
public static void main(String[]args){

Tree bt = new Tree ();

Random number = new Random();
int i;

for(i = 1; i<100; i++){
int randNum = number.nextInt(101);
if(randNum == 0){
i--;
}
else{
bt.insert(randNum);
}
}
bt.calculateHeights();
}
}

Node makeTree(int head, int tail){
    nodeMid = (head+tail)/2;
    this = new Node();
    if(head < nodeMid-1)
    {
        this.left = makeTree(head, nodeMid-1);
    }
    if(nodeMid < tail)
    {      
        this.right = makeTree(nodeMid, tail);
    }
    this.setValue(list[nodeMid]);
    return this;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote