快速排序,霸气。【循环美,只有low high在变】
只是这个地方写反了。
写成大于等于也可以,写成等于就报错。
import java.util.Arrays;
public class quickSort22 {
public static void main(String[] args) {
int a[]={7,6,4,2,99,-32,-3232,23232,32,9,1,22,3,1};
quickSort(a,0,a.length-1);
System.out.println(Arrays.toString(a));
}
public static void quickSort(int a[] , int low , int high){
if(low>high)
return;
int mid = part(a,low,high);
quickSort(a,low,mid-1);
quickSort(a,mid+1,high);
}
public static int part(int a[] , int low ,int high){
int pivot = a[low];
while(low<high){
while(low<high && a[high]>=pivot)
high--;
a[low] = a[high];
while(low<high && a[low]<=pivot)
low++;
a[high] = a[low];
}
a[low] = pivot;
return low;
}
}