Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SortableArrayListWithInsertionSort<T extends Comparable<T>>
- extends SortableArrayList<T>
- {
- public SortableArrayListWithInsertionSort(int capacity)
- {
- super(capacity);
- }
- // Sorts the sublist using Insertion Sort
- protected void sortSublist( int lowIndex, int highIndex) {
- if(lowIndex >= highIndex)
- return;
- int i = lowIndex + 1;
- int j = i;
- T temp = listItem[i];
- j=subHelper( j, temp);
- listItem[j] = temp;
- sortSublist( lowIndex + 1, highIndex);
- }
- int subHelper( int j, T b) {
- if(j <= 0 || listItem[j-1].compareTo(b) <= 1)
- return j;
- listItem[j] = listItem[j - 1];
- return subHelper( j-1, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement