SelectionSort is another sorting algorithm that has a performance of O(n²) like BubbleSort. It sorts an array of numbers by finding the smallest element in the unsorted part of the array and switching it with the current item. This is repeated until the entire array is sorted.
public static void selectionSort(int[] ia) { int l = ia.length; if (l == 1) return; for (int i = 0; i != l; i++) { int s = i; for (int j = i; j != l; j++) if (ia[j] < ia[s]) s = j; int t = ia[i]; ia[i] = ia[s]; ia[s] = t; } }