#include <bits/stdc++.h> using namespace std; void QuickSort(int a[],int l,int r) { int mid = a[(l+r)/2]; int lwalker = l; int rwalker = r; while (lwalker < rwalker) { while (a[lwalker] < mid) lwalker++; while (a[rwalker] > mid) rwalker--; if (lwalker <= rwalker) { swap(a[lwalker],a[rwalker]); lwalker++; rwalker--; for (int i = 0; i<10; i++) cout << a[i] << " "; cout << endl; } } if (lwalker < r) QuickSort(a,lwalker,r); if (rwalker > l) QuickSort(a,l,rwalker); } int main() { int a[] = {0,6,4,2,8,1,5,3,7,9}; for (int i = 0; i<10; i++) cout << a[i] << " "; cout << endl; QuickSort(a,0,9); for (int i = 0;i<10;i++) { cout << a[i] << " "; } cout << endl; return 0; }
快速排序
爱程序 不爱bug
爱生活 不爱黑眼圈
我和你们一样 我和你们不一样
我不是凡客 我要做geek