int myqsort_partition(int *A, int p, int r) { int pivot = A[r]; int store_idx = p; for(int idx = p; idx <= r; ++idx) { if(A[idx] < pivot) { std::swap(A[store_idx], A[idx]); store_idx++; } } std::swap(A[store_idx], A[r]); return store_idx; } void myqsort(int *A, int p, int r) { if(p < r) { int q = myqsort_partition(A, p, r); myqsort(A, p, q-1); myqsort(A, q+1, r); } }
.....
.....
.....
int A[] = {3, 2, 1, 4, 76, 9, 34, 3, 8}; int cnt = sizeof(A)/sizeof(A[0]); copy(A, A+cnt, ostream_iterator<int>(cout, ",")); cout << endl; myqsort(A, 0, cnt-1); copy(A, A+cnt, ostream_iterator<int>(cout, ",")); cout << endl;