排序算法——快速排序
Posted single-dont
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了排序算法——快速排序相关的知识,希望对你有一定的参考价值。
图示思想:
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;
以上是关于排序算法——快速排序的主要内容,如果未能解决你的问题,请参考以下文章