快速排序

 1 void QuickSort(int *array, int from, int to)
 2 {
 3     if(from>=to)return;
 4     int pivot = array[from]; 
 5 
 6     int i = from, j, temp;
 7     for(j = from + 1;j <= to;j++)
 8     {
 9         if(array[j] < pivot) 
10         {
11             i = i + 1;
12             temp = array[i];
13             array[i] = array[j];
14             array[j] = temp;
15         }
16 
17     }
18 
19     temp = array[i];
20     array[i] = array[from];
21     array[from] = temp;
22 
23     QuickSort(array,from,i-1);
24     QuickSort(array,i+1,to);
25 }

 快速排序每一次遍历完都把基准数放到正确的位置上,每一次遍历完所有比基准数小的数都在其左边,所有比基准数大的数都在其右边。

终于明白,“喜欢”是一种莫大的能量!
原文地址:https://www.cnblogs.com/tml839720759/p/3375062.html