public class QuickSort {
public static void main(String[] args) {
int array[] = { 32, 12, 32, 7, 78, 23, 45, 32, 66 };
quickSort(array, 0, array.length - 1);
System.out.println(Arrays.toString(array));
}
public static void quickSort(int array[], int left, int right) {
if (left >= right) {
return;
}
int i = left;
int j = right;
int key = array[left];
while (i < j) {
while (i < j && array[j] >= key) {
j--;
}
array[i] = array[j];
while (i < j && array[i] <= key) {
i++;
}
array[j] = array[i];
}
array[i] = key;
quickSort(array, left, i - 1);
quickSort(array, i + 1, right);
}
}
最简单的快速排序
最新推荐文章于 2022-04-19 18:49:15 发布