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

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 Solution

3.39 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Complete Program File SortedIntList class implementati... View full answer

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 Building Java Programs A Back to Basics Approach Questions!