Selection sort, fast row, row to take

Selection Sort

// The basic idea: Selection Sort (Selection-sort) is a simple and intuitive sorting algorithm.
// it works: First, find the minimum unsorted sequence (large) elements, storage location to start ordering sequence
// Then, continue to look for the smallest (large) elements from the remaining unsorted elements,
// then sorted into the end of the sequence. And so on, until all the elements are sorted completed

[7, 6, 5, 3, 1, 9, 4]
------------------------
[1, 6, 5, 3, 7, 9, 4]
[1, 3, 5, 6, 7, 9, 4]
[1, 3, 4, 6, 7, 9, 5]
[1, 3, 4, 5, 7, 9, 6]
[1, 3, 4, 5, 6, 9, 7]
[1, 3, 4, 5, 6, 7, 9]
[1, 3, 4, 5, 6, 7, 9]

    public static void main(String[] args) {

        int[] arr = {7, 6, 5, 3, 1, 9, 4};

        System.out.println(Arrays.toString(arr));
        System.out.println("------------------------");
        for (int i = 0; i < arr.length; i++) {
            int minIndex = i;
            for (int j = i; j < arr.length; j++) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
            }
            int temp = arr[minIndex];
            arr[minIndex] = arr[i];
            arr[i] = temp;

            System.out.println(Arrays.toString(arr));
        }
    }

https://www.cnblogs.com/snowcan/p/6243873.html

Guess you like

Origin www.cnblogs.com/antball/p/11544426.html
Row