Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
546 B
2
Indexable
Never
class List {
    int[] arr;
    int size;

    public void selectionSort() {
        int i, j, min;

        for (i = 0; i < size; i++) {
            min = i;

            for (j = i + 1; j < size; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }

            if (min != i) {
                swap(i, min);
            }
        }
    }

    private void swap(int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

}