自己写的快速排序,结果拍不出来,求解!!!
程序代码:
public class QuickSortTest{ public static void QuickSort(int[] a, int left, int right){ int i = left; int j = right; if(i > j){ return ; } int key = a[left]; while(true){ while(i < j){ if(key < a[i]){ int temp = a[j]; a[j] = a[i]; a[i] = temp; break; } else{ i++; } } while(i < j){ if(key > a[j]){ int temp = a[j]; a[j] = a[i]; a[i] = temp; break; } else{ j--; } } if(i == j){ break; } } QuickSort(a, left, i - 1); QuickSort(a, i + 1, right); } public static void main(String[] args){ int[] array = {32,21,45,6,7,34,89,65,22}; QuickSort(array, 0, array.length-1); for(int i = 0; i < array.length; i++){ System.out.print(array[i] + ","); } } }
这是结果 32,21,7,6,22,34,45,65,89