package com.lovcoding.day06;

import java.util.Arrays;

public class TestArr04_Sort_1 {
    //选择排序
    public static void main(String[] args) {
        int[] arr = {11,31,53,16,18,29,111,14,716,218,19,22,125,127,28,529,35,46,57,67,78,98};

        //排序
        for (int i = 0; i < arr.length-1; i++) {
            //最小值
            int min = arr[i];
            //索引
            int index = i;

            for (int j = i+1; j < arr.length ; j++) {
                if (arr[j] < min){
                    min = arr[j];
                    index = j;
                }
            }
            //判断最小值位置 和 i 是否相等
            if (index != i){
                int temp = arr[i];
                arr[i] = arr[index];
                arr[index] = temp;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
