quickSort

public class test3 {
    public static void main(String[] args) {
        int[] arr = { 49, 38, 65, 97, 23, 22, 76, 1, 5, 8, 2, 0, -1, 22 };
        quickSort(arr, 0, arr.length - 1);
        System.out.println("排序后:");
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void quickSort(int[] arr,int low,int hight){
        int left = low;
        int right = hight;
        if (left < right) {
            int temp = arr[left];
            while (left < right) {
                while (left < right && arr[right] >= temp) {
                    right--;
                }
                arr[left] = arr[right];
                while (left < right && arr[left] <= temp) {
                    left++;
                }
                arr[right] = arr[left];
            }
            arr[left] = temp;
            quickSort(arr, low, left - 1);
            quickSort(arr, left + 1, hight);
        }
    }
}
posted @ 2019-12-13 18:28  M_x_j  阅读(148)  评论(0编辑  收藏  举报