参考http://developer.51cto.com/art/201403/430986.htm
(有生动的图片讲解)
public class HelloWorld {
public static void main(String[] args) {
int[] a = {6,1,2,7,9,3,4,5,10,8};
sort(a,0,a.length-1);
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println();
}
public static void sort(int[] a,int left,int right){
if(left<right){
int i=left,j=right;
int data=a[left];//使用"最左边"的数字作为"基数"
while(i!=j){
while (i < j && a[j] >= data) j--;
while (i < j && a[i] <= data) i++;
if (i < j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
//交换"基数",实质上交换后的原来基数就是在数组中排序后的位置,新的基数作为下次排序的基数
a[left]=a[i];
a[i]=data;
sort(a,0,i-1);
sort(a,i+1,right);
}
}
}