快速排序及其优化
public class QuickSort {
public static void main(String[] args) {
int [] a ={1,2,3,0,9,8,7,6,5,4};
Sort(a,10);
for(int k=0;k<a.length ;k++){
System.out.print(a[k]+" ");
}
}
private static void Sort(int[] k,int n) {
QSort(k,0,n-1);
}
private static void QSort(int [] k,int low,int high) {
int point;
if(low<high){
point =Partition(k,low,high);
QSort(k,low,point-1);
QSort(k,point+1,high);
}
}
private static int Partition(int[] k,int low,int high) {
int point;
point=k[low];
while(low<high){
while(low<high&&k[high]>=point){
high--;
}
swap(k,low,high);
while(low<high&&k[low]<=point){
low++;
}
swap(k,low,high);
}
return low;
}
private static void swap(int[] k, int low, int high) {
int temp;
temp=k[low];
k[low]=k[high];
k[high]=temp;
}
}public class QuickSort {
public