@Test
public void testSort(){
int[] data = {5,1,9,7,2,3,0,4,8,6};
this.quickSort(data,0,data.length-1);
for(int n:data){
System.out.print(n+",");
}
}
private void quickSort(int[] array,int start,int end){
if(end>start) {
int pivot= this.sort(array, start, end);
this.quickSort(array, pivot + 1, end);
this.quickSort(array, start, pivot - 1);
}
}
private int sort(int[] array,int start,int end){
int pivot = array[start];
while(end>start){
while (end>start&&array[end]>=pivot){
end--;
}
array[start]=array[end];
while(end>start&&array[start]<=pivot){
start++;
}
array[end]=array[start];
}
array[start]=pivot;
return start;
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布