标签:turn color 快速 col ++ ima key i++ for
图示思想:
int Partition(int* a, int low, int high) { int pivotkey = a[low]; while (low < high) { while (low < high && a[high] >= pivotkey) high--; a[low] = a[high]; while (low < high && a[low] <= pivotkey) low++; a[high] = a[low]; } a[low] = pivotkey; return low; } void QuickSort(int* a, int low, int high) { if (low < high) { int pivotloc = Partition(a, low, high); QuickSort(a, low, pivotloc-1); QuickSort(a, pivotloc+1, high); } } int main() { int arr[] = { 9,2,3,1,5,4,7,8,6 }; int n = sizeof(arr) / sizeof(int); int low = 0, high = n - 1; QuickSort(arr, low,high); for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl; return 0; }
标签:turn color 快速 col ++ ima key i++ for
原文地址:https://www.cnblogs.com/single-dont/p/11354670.html