/**
 * @ProjectName driver-service
 * @ClassName SelectionSort
 * @Desicription TODO
 * @Author Zhang Xueliang
 * @Date 2019/12/17 13:49
 * @Version 1.0
 **/
public class SelectionSort {

    public static void main(String[] args) {
        int[] arr = {9,5,8,4,6,2,1,3,7};
        for (int k = 0; k < arr.length; k++) {
            int minPos = k;
            for (int i = k+1; i < arr.length; i++) {
                if (arr[i]<arr[minPos]) minPos=i;
            }
            int tmp = arr[k];
            arr[k]=arr[minPos];
            arr[minPos]=tmp;
        }

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

}

Java排序算法--选择排序算法_后台编程