Good day !

Need helps here.

I was told that I can search for a n-th smallest element in an array using the partition list function of quick sort, without having to sort it completely before getting the value.

For example, I got an array of 10 items. I would like to know the 3rd smallest element in the array.

I wonder how can I accomplish this ?

Thanks a lot.

SonicWave

p/s: Below is the funciton of the partition list i am using. THanks again.

void parti(int left, int right)
{
int pivot, l_hold, r_hold;

l_hold = left;
r_hold = right;
pivot = A[left];

while (left < right)
{
while ((A[right] >= pivot) && (left < right))
right--;
if (left != right)
{
A[left] = A[right];
left++;
}
while ((A[left] <= pivot) && (left < right))
left++;
if (left != right)
{
A[right] = A[left];
right--;
}
}
A[left] = pivot;
pivot = left;
left = l_hold;
right = r_hold;

displayArray();

if (left < pivot)
parti(left, pivot-1);
if (right > pivot)
parti(pivot+1, right);
}