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

Function introsort

CPP/sorting/intro_sort.cpp:82–98  ·  view source on GitHub ↗

Function to perform introsort on the given array

Source from the content-addressed store, hash-verified

80
81// Function to perform introsort on the given array
82void introsort(int a[], int *begin, int *end, int maxdepth)
83{
84 // perform insertion sort if partition size is 16 or smaller
85 if ((end - begin) < 16) {
86 insertionsort(a, begin - a, end - a);
87 }
88 // perform heapsort if the maximum depth is 0
89 else if (maxdepth == 0) {
90 heapsort(begin, end + 1);
91 }
92 else {
93 // otherwise, perform Quicksort
94 int pivot = randPartition(a, begin - a, end - a);
95 introsort(a, begin, a + pivot - 1, maxdepth - 1);
96 introsort(a, a + pivot + 1, end, maxdepth - 1);
97 }
98}
99
100int main()
101{

Callers 1

mainFunction · 0.85

Calls 3

insertionsortFunction · 0.85
heapsortFunction · 0.85
randPartitionFunction · 0.85

Tested by

no test coverage detected