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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started