Quicksort Pivot

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;
  }
}


next up previous
Next: Web Walk Up: EXAMPLES Previous: While in Russia...