public class QuickSort {
static int[] data = new int[]{50,10,90,30,70,40,80,60,20};
public static void main(String[] args) {
qSort(0 , data.length-1);
for(int i : data){
System.out.println(i);
}
}
private static void qSort(int low,int high){
if(low < high){
int pivot = partition(low , high);
qSort(low,pivot-1);
qSort(pivot+1,data.length-1);
}
}
private static int partition(int low,int high){
int pivotkey = data[low];
while(low < high){
while(low < high && data[high] >= pivotkey){
high --;
}
SwapUtil.swap(low, high, data);
while(low < high && data[low] <= pivotkey){
low ++;
}
SwapUtil.swap(low, high, data);
}
return low;
}
}
快速排序算法
最新推荐文章于 2020-10-13 10:04:31 发布