/**
* @param list
*/ public static void insertionSort(int[] list) {
int i, temp, j; for (i = 1; i < list.length; i++) {
temp = list[i]; for (j = i - 1; j >= 0; j--) { if (list[j] > temp) {
list[j + 1] = list[j];
} else { break;
}
}
list[j + 1] = temp;
System.out.println("Step " + i + " : " + Arrays.toString(list));
}
}
/**
* Sorts and returns the time taken in milliseconds.
*
* @param list
* @return
*/ public static double insertionSortTimeTaken(int[] list) { long startTime = System.nanoTime();
insertionSort(list); long timeTaken = System.nanoTime() - startTime; return timeTaken * Math.pow(10, -6);
}
}