![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <utility> 2 using std::swap; 3 4 int partition(int* array, int left, int right) 5 { 6 int index = left; 7 int pivot = array[index]; 8 swap(array[index], array[right]); 9 for (int i=left; i<right; i++) 10 { 11 if (array[i] > pivot) // 降序 12 swap(array[index++], array[i]); 13 } 14 swap(array[right], array[index]); 15 return index; 16 } 17 18 void qsort(int* array, int left, int right) 19 { 20 if (left >= right) 21 return; 22 int index = partition(array, left, right); 23 qsort(array, left, index - 1); 24 qsort(array, index + 1, right); 25 }