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:
![\begin{eqnarraystar}
\lefteqn{\hat{c}_t + \Phi(A_{t-1}, i_{t-1}, j_{t-1}) - \Phi...
...A_t[j_t] \le x)-\chi(A_t[i_t] \ge x)\ &=& 1+1-1-0 = 1 = c_t.\end{eqnarraystar}](img27.gif)
Note: This is assuming at most one value equal to the pivot.