Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int randomizedPartition(int a[], int left, int right)
- {
- srand(time(NULL)); //makes use of the computer's internal clock to control the choice of the seed.
- int random = left + rand() % (right - left);
- printf("%d ", a[random]);
- int aux = a[random];
- a[random] = a[right];
- a[right] = aux;
- return partition(a, left, right);
- }
- int randomizedQuickSelect(int a[], int left, int right, int y)
- {
- if (left >= right)
- return a[left];
- int x = randomizedPartition(a, left, right);
- if (x == y)
- return a[x];
- else
- if (x < y)
- return randomizedQuickSelect(a, x + 1, right, y);
- else
- return randomizedQuickSelect(a, left, x - 1, y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement