java之快速排序
public class quikSort {
private static int count =0 ;
public static int sort(int[] arry, int l, int h) {
int key = arry[l];
while (l < h) {
while (l < h && arry[h] >= key) {
h--;
}
arry[l] = arry[h];
while (l < h && arry[l] <= key) {
l++;
}
arry[h] = arry[l];
}
arry[l] = key;
System.out.print("第"+ count++ +"次排序:" );
for (int i = 0; i < arry.length; i++) {
System.out.print(arry[i] + " ");
}
System.out.print(" key是:"+key );
System.out.println();
return l;
}
public static void quiksort(int[] b, int low, int high) {
if (low < high) {
int index = sort(b, low, high);
quiksort(b, low, index - 1);
quiksort(b, index + 1, high);
}
}
public static void main(String[] args) {
int[] f = { 15, 11, 23, 2, 55, 4, 7, 88, 66, 10, 34, 55, 77 };
System.out.print("原数组:");
for (int i = 0; i < f.length; i++) {
System.out.print(f[i] + " ");
}
System.out.println();
quiksort(f, 0, f.length - 1);
}
}