Based on the implementation of ArrayIntList or ArrayList, write a class SortedIntList or SortedList that provides most
Question:
Based on the implementation of ArrayIntList or ArrayList, write a class SortedIntList or SortedList that provides most of the same operations but maintains its elements in sorted order. When a new value is added to the sorted list, rather than appending it to the end of the list, it is placed in the appropriate index to maintain sorted order of the overall list.
For efficiency, you should discover the appropriate place to add new values to the list by using a binary search. Shift elements as needed and add the element in the proper index to maintain sorted order. (Do not manually re-sort the elements such as by calling Arrays.sort .) You should also modify the class’s indexOf method to use a binary search to locate elements.
Since the list must remain sorted, your sorted list should not retain the following operations from ArrayIntList or ArrayList:
public void add(int index, int value)
public void set(int index, int value)
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp