partition (int a[], int low, int high, int *point)
{
int x, left, right, temp;
x=a[low]; /* the algorithm is trying to find the proper position of x*/
left = high;
right = low + 1;
while ( right < left)
{
while (a[right] <= x) && (right < left)
right ++;
while(a[left]>x)
up--;
if (right < left)
{ /*the two elements are on the wrong side interchange a[right] and a[left]*/
temp = a[right];
a[right] = a[left];
a[left] = temp;
right++;
left -- ;
}
}
/*interchange a[low] and a[left]*/
a[low]=a[left];
a[left]=x;
*point=left;
}
|