public class QSort {
void quickSort (int[] r) {
qSort(r, 1, r.length -1);
}
void qSort(int[] r, int low, int high) {
int pivot;
if(low < high) {
pivot = partition (r, low, high);
qSort(r, low, pivot - 1);
qSort(r, pivot + 1, high);
}
}
int partition (int[] r, int low, int high) {
int pivotKey;
pivotKey = r[low];
while (low < high) {
while(low < high && r[high] >= pivotKey) {
high --;
}
swap (r, low, high);
while(low < high && r[low] <= pivotKey) {
low ++;
}
swap (r, low, high);
}
return low;
}
void swap (int[] r, int i, int j) {
r[0] = r[i];
r[i] = r[j];
r[j] = r[0];
}
public static void main (String[] a) {
int[] r = {0, 108, 69, 75, 87, 89, 90, 99, 100, 1};
QSort qSort = new QSort();
qSort.quickSort(r);
System.out.println("显示排序后的结果");
for (int i = 1; i < r.length; i ++) {
System.out.println(r[i] + ",");
}
}
}