这段程序是我看过别的代码后自己想着写的,可是老出错,小弟水平浅看不出来,请各位帮忙看看,顺便指点一下小弟的排序算法
多谢了!
public class TestSort {
public static void main(String[] args) {
int[] i_arr = new int[]{ 12, 4, 8, 55, 6, 78, 43, 45, 6, 8 };
//bubbleSort(i_arr);
//selectionSort(i_arr);
//insertSort(i_arr);
quickSort(i_arr, 0, i_arr.length - 1);
for(int i=0; i<i_arr.length; i++) {
System.out.print(i_arr[i] + " ");
}
}
public static void quickSort(int[] a, int low, int high) {
if(low >= high)
return;
int start = low;
int end = high;
int pivot = a[low];
while(true) {
while(a[end] >= pivot)
end --;
while(a[start] <= pivot)
start ++;
if(start >= end)
break;
swap(a, start, end);
}
quickSort(a, low, start - 1);
quickSort(a, end + 1, high);
}
public static void swap(int[] a, int b, int c) {
int temp = a[b];
a[b] = a[c];
a[c] = temp;
}
}