Java快排
程序员文章站
2022-03-21 19:14:35
...
public static void quickSort(double[] array, int i, int j) { if (j <= i) return; int pivotIndext = (i + j) / 2; swap(array, pivotIndext, j); int k = partition(array, i - 1, j, array[j]); swap(array, j, k); quickSort(array, i, k - 1); quickSort(array, k, j); } public static int partition(double[] array, int left, int right, double pivot) { do { while (array[++left] < pivot) ; while ((left < right) & (pivot < array[--right])) ; swap(array, left, right); } while (left < right); return 0; } public static void swap(double[] data, int a, int b) { double t = data[a]; data[a] = data[b]; data[b] = t; }
上一篇: jvm内存区域
下一篇: C#可选参数与具名参数