快速排序图解:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
==========================================================================================================================
==========================================================================================================================
java 代码的实现:

1 package main.test; 2 3 public class KSSort { 4 public static int Partition(int[] a, int p, int r) { 5 int x = a[r - 1]; 6 int i = p - 1; 7 int temp; 8 for (int j = p; j <= r - 1; j++) { 9 if (a[j - 1] <= x) { 10 // 交换(a[j-1],a[i-1]); 11 i++; 12 temp = a[j - 1]; 13 a[j - 1] = a[i - 1]; 14 a[i - 1] = temp; 15 } 16 } 17 //交换(a[r-1,a[i+1-1]); 18 temp = a[r - 1]; 19 a[r - 1] = a[i + 1 - 1]; 20 a[i + 1 - 1] = temp; 21 return i + 1; 22 } 23 24 25 public static void QuickSort(int[] a,int p,int r){ 26 if(p<r){ 27 int q=Partition(a,p,r); 28 QuickSort(a,p,q-1); 29 QuickSort(a,q+1,r); 30 } 31 } 32 33 static void print(int[] a) { 34 for (int values : a 35 ) { 36 System.out.print(values+" | "); 37 } 38 } 39 40 41 public static void main(String[] args) { 42 int[] a={7,10,3,5,4,6,2,8,1,9}; 43 QuickSort(a,1,10); 44 print(a); 45 46 47 } 48 49 50 }