java 快速排序

来源:互联网 发布:神仙劫翅膀进阶数据 编辑:程序博客网 时间:2024/04/27 18:10

public class QuickSort(){
public static void main(String[] args){
int [] a = {123,33,5,6,6,845,2,3};
quict(a);
}
public static void quick(int [] a){
if(a.length >0){
quickSort(a,0,a.length-1);
}
}
public static void quickSort(int[] a , int low , int high){
if(low < high){
int middle = getMiddle(a , low , high);
quickSort(a , 0 , middle -1);
quickSort(a , middle+1,high);
}
}
public static int getMiddler(int[] a, int low ,int high){
int temp = a[low];
while(low < high){
while(low < hight&&a[hight] >=temp){
hight–;
}
a[low] = a[hight];
while(low < high &&a[low]<=temp){
low++;
}
a[low] =temp;
return low;
}
}
}

0 0
原创粉丝点击