Example #1
0
void qsortrand (int *a, int p, int r)
{
    if (p<r)
    {
        int pivot=rand_partition(a, p, r);
        qsortrand(a,p,pivot-1);
        qsortrand(a,pivot+1,r);
    }
}
Example #2
0
	static void rand_select(Data a[], int b[], int p, int r, int i)
	{
		if (p >= r)
			return;
		// find q so that 
		// a[p..q] >= a[q] and a[q+1..r] < a[q] 
		int q = rand_partition(a, b, p, r);
		// k is the count of a[p..q]
		int k = q - p + 1;
		// if the number of maximus is more than wanted
		if (i < k)
			rand_select(a, b, p, q - 1, i);
		// if the number of maximums is less than wanted
		else if (i > k)
			rand_select(a, b, q, r, i);
	}