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); } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10674.html