选择排序 Selection sort

static void selection_sort(int[] unsorted) {
            for (int i = 0; i < unsorted.Length; i++) {
                int min = unsorted[i], min_index = i;
                for (int j = i; j < unsorted.Length; j++) {
                    if (unsorted[j] < min) {
                        min = unsorted[j];
                        min_index = j;
                    }
                }
                if (min_index != i) {
                    int temp = unsorted[i];
                    unsorted[i] = unsorted[min_index];
                    unsorted[min_index] = temp;
                }
            }
        }

有改进的方法,二路选择排序,一次循环中找出最大值和最小值

你可能感兴趣的:(选择排序 Selection sort)