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);
        }
    }
}
原文地址:https://www.cnblogs.com/mxj961116/p/12036735.html