10.16易科

public static void main(String[] args) {
        int arr[] = {6,1,3,2,9,7,5,4,8};
        quickSort(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
}
public static void quickSort(int[] arr,int left,int right) {
    if(left>right) {
        return;
    }
    int base = arr[left];
    int i = left;
    int j = right;
    while(i!=j) {
        while(arr[j]>=base&&i<j) {
            j--;
        }
        while(arr[i]<=base&&i<j) {
            i++;
        }
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
    arr[left] = arr[i];
    arr[i] = base;
    quickSort(arr,left,i-1);
    quickSort(arr,i+1,right);
}

快速排序

标签

评论

this is is footer