java快速排序算法代码
package Mypackage; public class QuickSort { public static void main(String[] args) { int[] arr = { 2, 5, 4, 3, 7, 0, 9, 1, 6, 8 }; quickSort(arr, 2, 7); for (int i = 0; i < arr.length; i++) System.out.print(arr[i] + " "); } public static void quickSort(int[] arr, int low, int high) { int i = 0, j, key = 0; if (low < high) { key = arr[low]; i = low; j = high; while (i < j) { while (i < j && arr[j] > key) j--; if (i < j) arr[i++] = arr[j]; while (i < j && arr[i] < key) i++; if (i < j) arr[j--] = arr[i]; } } arr[i] = key; if (i > low + 1) quickSort(arr, low, i - 1); if (i < high - 1) quickSort(arr, i + 1, high); } }