public class InsertionSorter extends Sorter { public InsertionSorter(int numItems){ super(numItems); } public InsertionSorter(int numItems, int seed){ super(numItems, seed); } @Override public void sort(){ //the array is divided in two: the sorter part is all the indices we have already process, //the unsorted part is the current index to the end. //for each item in the array, put it where it belongs in the sorted portion of the array for(int i = 1; i < data.length; i++){ int item = data[i]; int index = i; //put item data[i] in the right place within the sorted part of the list //shift every value greater than item right by one while(index > 0 && data[index-1] > item){ data[index ] = data[index-1]; index--; } data[index] = item; } } }