快速排序java代码实现:
public class QuickSort {
public static void main(String[] args) {
int[] arr = { 2, 3, 6, 1, 34, 32, 8, 65, 9, 24, 0, 2 };
quickSort(arr, 0, arr.length - 1);
for (int i : arr) {
System.out.print(i + ",");
}
}
private static void quickSort(int[] arr, int low, int hight) {
if (hight < low) {
return;
}
int i = low;
int j = hight;
int index = (low + hight) / 2;
int temp = arr[index];
while (i < j) {
while (i < j && arr[j] >= temp) {
j--;
}
while (i < j && arr[i] <= temp) {
i++;
}
if (i < j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
arr[index] = arr[i];
arr[i] = temp;
quickSort(arr, 0, i - 1);
quickSort(arr, i + 1, hight);
}
}