MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / randPartition

Function randPartition

CPP/sorting/intro_sort.cpp:62–72  ·  view source on GitHub ↗

Quicksort randomized partition to rearrange elements across pivot

Source from the content-addressed store, hash-verified

60
61// Quicksort randomized partition to rearrange elements across pivot
62int 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
75void heapsort(int *begin, int *end)

Callers 1

introsortFunction · 0.85

Calls 2

swapFunction · 0.70
partitionFunction · 0.70

Tested by

no test coverage detected