class Exercise6 { // sort array a in ascending order using the "selection sort" algorithm public static void sort(int[] a) { int n = a.length; int i = 0; while (i < n-1) { int j = minimum(a, i); if (i != j) { int e = a[i]; a[i] = a[j]; a[j] = e; } i = i+1; } } // returns position of smallest element in a[i..] public static int minimum(int[] a, int i) { int n = a.length; int p = i; int m = a[p]; int j = i+1; while (j < n) { if (a[j] < m) { p = j; m = a[p]; } j = j+1; } return p; } }