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)

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: