快速排序JAVA实现:
public class FastSort { public static void swap(int[] array, int i, int j) { int tmp = array[i]; array[i] = array[j]; array[j] = tmp; } public static void sort(int[] array, int first, int end) { if (first >= end) { return; } int x = array[first]; int i = first; int j = end + 1; while (true) { while (array[++i] < x && i < end) ; while (array[--j] > x) ; if (i >= j) { break; } swap(array, i, j); } swap(array, first, j); sort(array, first, j - 1); sort(array, j + 1, end); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] array = { 3, 2, 7, 2, 5, 1, 9, 2, 8, 1 }; sort(array, 0, 9); for (int i : array) { System.out.print(i + " "); } } }