public static int[] quickSort(int[] arr, int low, int heigh) { if(low < heigh){ int division = partition(arr, low, heigh); quickSort(arr, low, division - 1); quickSort(arr, division + 1, heigh); } return arr; } // 分水岭,基位,左边的都比这个位置小,右边的都大 private static int partition(int[] arr, int low, int heigh) { int base = arr[low]; //用子表的第一个记录做枢轴(分水岭)记录 while (low < heigh){ //更改下面两个while循环中的<=和>=,即可获取到从大到小排列 //从表的两端交替向中间扫描,从小到大排列 while (low < heigh && arr[heigh] >= base){ heigh--; } // 如果高位小于base,base 赋值给 当前 heigh 位,base 挪到(互换)到了这里,heigh位右边的都比base大 swap(arr, heigh, low); while(low < heigh && arr[low] <= base){ low++; } // 如果低位大有base, swap(arr, heigh, low); } //现在low=heigh return low; } //交换大小 private static void swap(int[] arr, int heigh, int low) { int temp = arr[heigh]; arr[heigh] = arr[low]; arr[low] = temp; }