排序算法-快速排序
程序员文章站
2022-03-24 15:33:06
...
public static void quick_sort(int[] a, int begin, int end){
int start = 0;
if (begin < end) {
start = a[begin];
int low = begin;
int high = end;
while(low < high){
while(low < high && a[high] > start){
high --;
}
a[low] = a[high];
while(low < high && a[low] <= start){
low ++;
}
a[high] = a[low];
}
a[low] = start;
TIMES ++;
quick_sort(a, begin, low - 1);
quick_sort(a, low + 1, end);
}
}
public static int TIMES = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = {21,30,2,5,8,12,44,55,63,63,65};
TIMES = 0;
quick_sort(a, 0, a.length - 1);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]+",");
}
System.out.println("Quick Sort times : "+TIMES);
}
下一篇: 选择排序原理及代码实现