voidmyqsort(int *a, int left, int right) { if (left >= right) return;
int last = left; int mid = left + (right- left)/2; swap(a[mid], a[left]); for(int i = left +1; i<= right; i++){ if (a[i] < a[left]) swap(a[i],a[++last]); //此处始终保证了last所指向的元素的后一个元素大于等于划分点,并且(left +1, last)的所有元素小于划分点 } swap(a[left], a[last]);
myqsort(a, left, last -1); myqsort(a, last + 1, right); }
intmain() { int arr[] ={9,4,1,2,3,81,1,2,3,91,99,8,7,8,5}; int length = sizeof(arr)/sizeof(int);