选择排序

public static void sort(int[] arr) {
    int n = arr.length;
    for (int i = 0; i < n; i++) {
        // 寻找[i, n)区间里的最小值索引
        int mixIndex = i;
        for (int j = i + 1; j < n; j++) {
            if (arr[j] < arr[mixIndex]) {
                swap(arr, j, mixIndex);
            }
        }
    }
}

results matching ""

    No results matching ""