package _04_常见算法;

public class Test7 {
    public static void main(String[] args) {
        /**
         * 选择排序
         */
        int[] arr = {1,5,4,3,2};
        // 0 -4  0 1 2 3
        for (int i = 0; i < arr.length-1; i++) {
            /**
             * 0   1234
             * 1   234
             * 2   34
             * 3   4
             */
            for (int j = 1 + i; j < arr.length; j++) {
                if(arr[i] > arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }

        // 遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"  ");
        }
    }
}
