I've written a stable implementation of insertion sort, that sorts an array in ascending order.
Please let me know of any improvements/optimisations that can be made.
import java.util.List;
public class InsertionSort {
public static void start(List<Integer> arrayToSort){
for(int i = arrayToSort.size() - 1; i > 0; i--){ // i is the leftmost index of sorted elements
// j is the index at which the new element inserted in the sorted part of the array
for(int j = arrayToSort.size() - 1; j >= i; j--){
if(arrayToSort.get(i - 1) > arrayToSort.get(j)){
insert(i - 1, j + 1, arrayToSort);
break;
}
}
}
}
private static void insert(int source, int destination, List<Integer> arrayToSort){
arrayToSort.add(destination, arrayToSort.get(source));
arrayToSort.remove(source);
}
}