完整代码:http://yuncode.net/code/c_503e1e448ba7745
核心代码:
08 int partition ( int a[], int low, int high )
09 {
10 //选择第一个a[low]作为划分的临界值
11 while ( low < high )
12 {
13 while ( low < high && a[low] <= a[high] ) high--;
14 swap ( a[low], a[high] );
15 while ( low < high && a[low] <= a[high] ) low++;
16 swap ( a[low], a[high] );
17 }
18 return low;
19 }
20
21 void Qsort ( int a[], int low, int high )
22 {
23 if ( low > high ) return;
24 int p = partition ( a, low, high );
25 Qsort ( a, low, p-1 );
26 Qsort ( a, p+1, high );
27 }