Another O(n²) sorting algorithm, however it’s more efficient than most O(n²) algorithms like BubbleSort and SelectionSort.
public static void insertionSort(int[] ia) {
int l = ia.length;
if (l == 1)
return;
for (int i = 0; i != l; i++)
for (int j = i; j != 0; j--)
if (ia[j] < ia[j - 1]) {
int t = ia[j];
ia[j] = ia[j - 1];
ia[j - 1] = t;
}
}