Quicksort randomized partition to rearrange elements across pivot
| 60 | |
| 61 | // Quicksort randomized partition to rearrange elements across pivot |
| 62 | int randPartition(int a[], int low, int high) |
| 63 | { |
| 64 | // choose a random index between `[low, high]` |
| 65 | int pivotIndex = rand() % (high - low + 1) + low; |
| 66 | |
| 67 | // swap the end element with the element present at a random index |
| 68 | swap(a[pivotIndex], a[high]); |
| 69 | |
| 70 | // call the partition procedure |
| 71 | return partition(a, low, high); |
| 72 | } |
| 73 | |
| 74 | // Function to perform heapsort on the given range of elements |
| 75 | void heapsort(int *begin, int *end) |