Question: Implement the ADT sorted list by using a binary search tree (BST). Use the posted SortedListInterface and BST implementation. In addition to implementing a toArray

Implement the ADT sorted list by using a binary search tree (BST). Use the posted SortedListInterface and BST implementation.

In addition to implementing a toArray method, your SortedList class should implement a toString method (see test client code below).

You can use the following methods for your test client:

public static void main(String[] args) { SortedList numbers = new SortedList(); // empty list Random randy = new Random(); // make sure to import java.util.Random; // have randy add 20 random numbers, each between 1 and 100, to the list for (int count=1; count<=20; count++) { numbers.add( 1+randy.nextInt(100) ); } // end for System.out.println("Numbers: ------------------------------"); displayUsingArray(numbers); System.out.println("------------------------------"); // have randy randomly look for 10 numbers from the list for (int count=1; count<=20; count++) { int element = 1 + randy.nextInt(100); if (numbers.contains( element )) { System.out.printf("Element %d is in the list ", element); } else { System.out.printf("Element %d is not in the list ", element); } } // end for System.out.println("------------------------------ Numbers: "); System.out.println(numbers); // only works if toString is implemented in SortedList System.out.println("------------------------------"); // have randy randomly remove 10 numbers from the list for (int count=1; count<=20; count++) { int element = 1 + randy.nextInt(100); if (numbers.remove( element )) { System.out.printf("Element %d removed from the list ", element); } else { System.out.printf("Element %d was not found in the list ", element); } } // end for System.out.println("------------------------------ Numbers: "); System.out.println(numbers); // only works if toString is implemented in SortedList } // end main static void displayUsingArray(SortedList nums) { Object[] array = nums.toArray(); for (int index=0; index

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!