选择排序

 

 

public class MySelectSort {
    /*
    选择排序
     */
    public static void main(String[] args) {
        int num[] = {10,8,33,54,1,6,12,43,32,27};
        selectSort(num);
        for (int i = 0; i < num.length; i++) {
            System.out.print(num[i] + " ");
        }
    }

    private static void selectSort(int[] num) {
        for (int i = 0; i < num.length; i++) {
            int index = i;
            for (int j = i+1; j < num.length ; j++) {
                if(num[j] < num[index] ){
                    index = j;
                }
            }
            int temp = num[index];
            num[index] = num[i];
            num[i] = temp;
        }
    }
}

  

posted on 2020-07-22 09:22  含光Aries  阅读(157)  评论(0编辑  收藏  举报