public class Test {
public static void main(String[] args) {
int[] a= new int[] {1,2,3,2,3,3,2,3,2,5,5,2,5,1,4};
quickSort(a, 1, 14);
for (int i : a) {
System.out.print(i);
}
}
public static void quickSort(int[] numbers, int start, int end) {
if (start < end) {
int base = numbers[start]; // 选定的基准值(第一个数值作为基准值)
int temp; // 记录临时中间值
int i = start, j = end;
do {
while ((numbers[i] < base) && (i < end))
i++;
while ((numbers[j] > base) && (j > start))
j--;
if (i <= j) {
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
i++;
j--;
}
} while (i <= j);
if (start < j)
quickSort(numbers, start, j);
if (end > i)
quickSort(numbers, i, end);
}
}
public static void main(String[] args) {
int[] a= new int[] {1,2,3,2,3,3,2,3,2,5,5,2,5,1,4};
quickSort(a, 1, 14);
for (int i : a) {
System.out.print(i);
}
}
public static void quickSort(int[] numbers, int start, int end) {
if (start < end) {
int base = numbers[start]; // 选定的基准值(第一个数值作为基准值)
int temp; // 记录临时中间值
int i = start, j = end;
do {
while ((numbers[i] < base) && (i < end))
i++;
while ((numbers[j] > base) && (j > start))
j--;
if (i <= j) {
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
i++;
j--;
}
} while (i <= j);
if (start < j)
quickSort(numbers, start, j);
if (end > i)
quickSort(numbers, i, end);
}
}
}
转载至 :http://www.cnblogs.com/sevenyuan/archive/2009/12/04/1616897.html
仅用于个人学习