Please use the information in the second screenshot about the BST class and Node class to create a class BSTApp.
Please make sure to use the following code as a starting point.
import java.util.*;
public class BSTTest{
public static void main(String[] args) {
// perform at least one test on each operation of your BST
}
private int[] randomArray(int size) {
// remove the two lines
int[] arr = new int[1];
return arr;
}
// the parameters and return are up to you to define; this method needs to be uncommented
// private test() {
//
// }
}
Base of class Node
public class Node {
int key;
Node left, right, parent;
public Node() {}
public Node(int num) {
key = num;
left = null;
right = null;
parent = null;
}
}
Base of class BST
import java.util.*;
class BST {
// do not change this
private Node root;
private ArrayList<Integer> data;
// DO NOT MODIFY THIS METHOD
public BST() {
root = null;
data = new ArrayList<Integer>(0);
}
// DO NOT MODIFY THIS METHOD
public ArrayList<Integer> getData() {
return data;
}
// DO NOT MODIFY THIS METHOD
public void inOrderTraversal() {
inOrderTraversal(root);
}
// DO NOT MODIFY THIS METHOD
private void inOrderTraversal(Node node) {
if (node != null) {
inOrderTraversal(node.left);
data.add(node.key);
inOrderTraversal(node.right);
}
}
// search
public boolean search(int target) {
// remove this line
return false;
}
// insert
public Node insert(int target) {
// remove this line
return root;
}
// note: you may need to implement several supporting methods for delete
public Node delete(int target) {
// remove this line
return root;
}
// you are welcome to add any supporting methods
}
Step by stepSolved in 3 steps
- Please use the template provided below and make sure the output matches exactly. import java.util.Scanner;import java.util.ArrayList; public class PhotoLineups { // TODO: Write method to create and output all permutations of the list of names. public static void printAllPermutations(ArrayList<String> permList, ArrayList<String> nameList) { } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> nameList = new ArrayList<String>(); ArrayList<String> permList = new ArrayList<String>(); String name; // TODO: Read in a list of names; stop when -1 is read. Then call recursive method. }}arrow_forwardWrite all the code within the main method in the TestTruck class below. Implement the following functionality. Construct two Truck objects: one with any make and model you choose and the second object with gas tank capacity 10. If an exception occurs, print the stack trace. Print both Truck objects that were constructed. import java.lang.IllegalArgumentException ; public class TestTruck { public static void main( String[] args ) { // write your code herearrow_forwardpublic class arrayOutput ( public static void main (String [] args) { final int NUM ELEMENTS = 3; int[] userVals = new int [NUM_ELEMENTS]; int i; } Type the program's output userVals [0] = 2; userVals [1] = 6; userVals [2] = 8; for (i = userVals.length - 1; i >= 0; −−1) { System.out.println(userVals [1]); } C.C. ? ? ??arrow_forward
- Use the ArrayList class Add and remove objects from an ArrayList Protect from index errors when removing Practice with input loop Details: This homework is for you to get practice adding and removing objects from an ArrayList. The Voter class was used to create instances of Voters which held their name and a voter identification number as instance variables, and the number of instances created as a static variable. This was the class diagram: The constructor takes a string, passed to the parameter n, which is the name of the voter and which should be assigned to the name instance variable. Every time a new voter is created, the static variable nVoters should be incremented. Also, every time a new voter is created, a new voterID should be constructed by concatenating the string “HI” with the value of nVoters and the length of the name. For example, if the second voter is named “Clark Kent”, then the voterID should be “HI210” because 2 is the value of nVoters and 10 is the number…arrow_forwardNeed help with menu loop pleasearrow_forwardIn netbeans using Java create a class Palindrome2 which replaces the while loop of problem 13 with a for loop.arrow_forward
- starter code import java.util.ArrayList; public class SortsTracing { //Note: Style is not required for this file //for reference public ArrayList<int[]> SelectionSortExampleList() { ArrayList<int[]> answer = new ArrayList<int[]>(); answer.add(new int[]{-1, 20, 18, 17, 9, 4, 2, 0, 40}); answer.add(new int[]{-1, 0, 18, 17, 9, 4, 2, 20, 40}); answer.add(new int[]{-1, 0, 2, 17, 9, 4, 18, 20, 40}); answer.add(new int[]{-1, 0, 2, 4, 9, 17, 18, 20, 40}); answer.add(new int[]{-1, 0, 2, 4, 9, 17, 18, 20, 40}); answer.add(new int[]{-1, 0, 2, 4, 9, 17, 18, 20, 40}); // etc... (the rest of the iterations) return answer; } public ArrayList<int[]> InsertionSortRandomList() { ArrayList<int[]> answer = new ArrayList<int[]>(); answer.add(new int[]{30, 62, 5, 109, 66, 17, 51, 18}); // TODO return answer; } public ArrayList<int[]>…arrow_forwardJavaTimer.java: import java.util.Arrays;import java.util.Random; public class JavaTimer { // Please expand method main() to meet the requirements.// You have the following sorting methods available:// insertionSort(int[] a);// selectionSort(int[] a);// mergeSort(int[] a);// quickSort(int[] a);// The array will be in sorted order after the routines are called!// Be sure to re-randomize the array after each sort.public static void main(String[] args) {// Create and initialize arraysint[] a = {1, 3, 5}, b, c, d;// Check the time to sort array along startTime = System.nanoTime();quickSort(a);long endTime = System.nanoTime();long duration = (endTime - startTime) / 1000l;// Output resultsSystem.out.println("Working on an array of length " + a.length + ".");System.out.println("Quick sort: " + duration + "us.");}// Thanks to https://www.javatpoint.com/insertion-sort-in-javapublic static void insertionSort(int array[]) {int n = array.length;for (int j = 1; j < n; j++) {int key = array[j];int…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY