#include <iostream> using namespace std; int a[] = {223, 1, 32, 12, 4, 6, 3}; int partition(int *a, int low, int high) { int pivotkey, temp; //privotkey 分割轴; 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 qSort(int *a, int low, int high) { int pivotloc; if(low < high) { pivotloc = partition(a, low, high); //将数组一分为二 pivotloc为分割轴 qSort(a, low, pivotloc-1); qSort(a, pivotloc+1, high); } } void quickSort(int *a, int size) { qSort(a, 0, size-1); } int main() { int size = sizeof(a)/sizeof(int); quickSort(a, size); for(int i=0; i<size; i++) { cout<<a[i]<<" "; } system("pause"); return 0; }