3、选择排序(最小值/最大值)

public class Sort {
    public static void main(String[] args) {
        int[] arr = RandomUtil.randomInts(100);
        System.out.println(JSONObject.toJSON(arr));
        System.out.println();

        quickSort(arr, 0, arr.length - 1);
        System.out.println(JSONObject.toJSON(arr));
    }

    /**
     * 选择排序(最小值/最大值)
     *
     * @param arr
     */
    private static void selectSort(int[] arr) {
        System.out.println(JSONObject.toJSON(arr));
        System.out.println();
        int temp = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(JSONObject.toJSON(arr));
    }

 

posted @ 2020-11-13 11:34  SweetBaby。  阅读(213)  评论(0编辑  收藏  举报