快速排序代码:
//快速排序
public class Main{
private static int count=1;
public static int[] arry={6, 3, 1, 2, 5, 4, 9, 7, 10, 8};
public static void main(String []args){
quickSort(0,arry.length-1);
/* quickSort(1,4);
quickSort(1,2);
quickSort(7,arry.length-1);
quickSort(6,arry.length-1);*/
for(int i=0;i<arry.length;i++){
System.out.print(arry[i]+" ");
}
}
public static void quickSort(int left,int right){
//递归算法出口
if(left>right){
return;
}
int temp=arry[left];
int i=left;
int j=right;
int t;
while(i!=j){
//先从右边找
while(i<j&&arry[j]>=temp){
j--;
}
while (i<j&&arry[i]<=temp){
i++;
}
if(i<j){
t=arry[j];
arry[j]=arry[i];
arry[i]=t;
}
}
arry[left]=arry[i];
arry[i]=temp;
quickSort(left,i-1);
quickSort(i+1,right);
}
}