package sort;

import java.util.Arrays;
//选择排序模板
public class select_sort {
    public static void main(String[] args) {
        int[] arr = new int[]{10,20,-10,40,199,2,100};
        select_sort(arr);
        System.out.println(Arrays.toString(arr));
    }
   public static void select_sort(int[] arr){
        for(int i = 0;i<arr.length-1;i++){
            int min = arr[i];
            int min_index = i;
            for(int j = i+1;j<arr.length;j++){
                if(min>arr[j]){
                    min = arr[j];
                    min_index = j;
                }
            }
            if(i != min_index){
                arr[min_index] = arr[i];
                arr[i] = min;
            }

        }
   }
}