/// Selection sort that shows the array after each pass.
int[] selectionSortVerbose(int[] items) {
    int[] result = Arrays.copyOf(items, items.length);

    for (int i = 0; i < result.length; i++) {
        int smallest = i;
        for (int j = i + 1; j < result.length; j++) {
            if (result[j] < result[smallest]) {
                smallest = j;
            }
        }
        int temp = result[i];
        result[i] = result[smallest];
        result[smallest] = temp;

        int[] sortedPart = Arrays.copyOfRange(result, 0, i + 1);
        int[] rest = Arrays.copyOfRange(result, i + 1, result.length);
        IO.println("Pass " + (i + 1) + ": " + Arrays.toString(sortedPart) + " "
                + Arrays.toString(rest));
    }

    return result;
}

void main() {
    selectionSortVerbose(new int[] {64, 25, 12, 22, 11});
}

// From Groundwork, chapter 11 (ch11-searching-and-sorting), box 5.
// This example is from Groundwork, licensed CC BY-NC-SA 4.0.
// Run with: java ch11_05.java
