int partition( vector<int> & A, int start, int end, int pivot_position ) { int x = A[pivot_position]; int i = start - 1; int j = end + 1; while( true ) { do j--; while( A[j] > x ); do i++; while( A[i] < x ); if( i < j ) swap( A, i, j ); else return j; } }
(1) Decrement j, (2) Increment i, (3) Swap.
In all cases, ct = 1.
(1) Decrement j:
(2) Increment i:
(3) Swap:
Note: This is assuming at most one value equal to the pivot.