提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
快速排序的Java实现
class Quick_Sort { /*来自 nowjava*/ // Conquer public static int Parition(int[] array, int left, int right) { int pivot = array[left]; int index = right; int temp; for(int j = right; j > left; j--) { if(array[j] > pivot) {/** N o w J a v a . c o m 提供 **/ temp = array[j]; array[j] = array[index]; array[index] = temp; index--; } } array[left] = array[index]; array[index] = pivot; return index; } // Divide array into halves public static void Quick(int[] array, int left, int right) { if(left < right) { int pivot = Parition(array, left, right); Quick(array, left, pivot - 1); Quick(array, pivot + 1, right); } } public static void QuickSort(int array[], int size) { Quick(array, 0, size - 1); } // function ro print array public static void Print_Array(int[] array, int size) { for(int i = 0; i < size; i++) System.