/// Returns a sorted copy of items, using selection sort.
int[] selectionSort(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;
    }

    return result;
}

void main() {
    int[] numbers = {64, 25, 12, 22, 11};
    IO.println(Arrays.toString(selectionSort(numbers)));
}

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