// method to sort an array, using selection sort. public void sort(int[] a) { selSort(a, 0); } // sort all elements in a from a[start]..a[length-1] private void selSort(int[] a, int start) { if (start < a.length - 1) { int smallestIndex = indexOfSmallest(start); int temp = a[start]; a[start] = a[smallestIndex]; a[smallestIndex] = temp; selSort(a, start + 1); } } // Return the smallest element at index start or higher private int indexOfSmallest(int[] a, int start) { int smallestIndex = start; for (int i = start + 1; i < a.length; i++) { if (a[i] < a[smallestIndex]) { smallestIndex = i; } } return smallestIndex; }