That's a lot of loops for a simple partition algorithm. Try something along these lines and call me in the morning:
Code:
int partition ( int a[], int low, int high )
{
int pivot;
int i, prev;
swap ( a[low], a[( low + high ) / 2] );
pivot = a[low];
prev = low;
for ( i = low + 1; i <= high; i++ ) {
if ( a[i] < pivot )
swap ( a[++prev], a[i] );
}
swap ( a[low], a[prev] );
return prev;
}
void quicksort ( int a[], int low, int high )
{
int pivot;
if ( low >= high )
return;
pivot = partition ( a, low, high );
quicksort ( a, low, pivot - 1 );
quicksort ( a, pivot + 1, high );
}