Loading…
Loading…
Finds the minimum of the unsorted region on each pass and places it at the front.
Start selection sort.
1void selectionSort(int[] a) {2 int n = a.length;3 for (int i = 0; i < n - 1; i++) {4 int min = i;5 for (int j = i + 1; j < n; j++)6 if (a[j] < a[min]) min = j;7 int t = a[i]; a[i] = a[min]; a[min] = t;8 // a[i] is now sorted9 }10}