Warning: Attempt to read property "ID" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 471

Warning: Attempt to read property "display_name" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 480

Warning: Attempt to read property "display_name" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 487

Warning: Attempt to read property "description" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 489

Warning: Attempt to read property "ID" on bool in /www/wwwroot/129.28.78.18/wp-content/themes/storeys-pro/wbc/components/og_schema/wb_og_schema.php on line 493

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);
}

快速排序

评论留言