Question: Implement the SortedList interface. There is no specific implementation or algorithm that you must use; you should determine the best way to implement this for

Implement the SortedList interface. There is no specific implementation or algorithm that you must use; you should determine the best way to implement this for yourself.

A SortedList allows for three operations:

1. insert(): Adds an element to the list

2. get(): Gets the "i"-the smallest number in the list

3. size(): Returns the size of the list.

A user should be able to use a SortedList by adding elements in any order, and then iterating through the list and getting the elements back in sorted order.

For example: SortedList l;

// some code which initializes l

l.insert(5);

l.insert(3);

l.insert(7);

l.insert(20);

l.insert(-30);

for (int i = 0; i < l.size(); i++) {

System.out.println(l.get(i));

}

This should output: -30

3 5 7 20

Directions

This project has two parts: a programming part and a written part. For the programming part:

1. Implement the SortedList interface.

2. Write main class that tests out the interface.

For the written part, you must determine the asymptotic running time ("Big Oh") of all of the functions. You should explain the tradeoffs: for example, you may have decided to make the insert method faster at the expense of the get method, or the other way around.

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 Programming Questions!