2020-10-06 15:01:50 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-18 01:30:06 +02:00
|
|
|
int pivotPartition(std::vector<uint32_t>& a, int p, int r) {
|
|
|
|
|
|
|
|
return partition(a, p, r);
|
2020-10-06 15:01:50 +02:00
|
|
|
}
|
|
|
|
|
2020-10-18 01:30:06 +02:00
|
|
|
void quicksort(std::vector<uint32_t>& a, int p, int r)
|
2020-10-14 00:26:32 +02:00
|
|
|
{
|
2020-10-18 01:30:06 +02:00
|
|
|
if (p < r) {
|
|
|
|
int i = pivotPartition(a, p, r);
|
|
|
|
#ifdef PARTITION_TYPE_LOMUTO
|
|
|
|
quicksort(a, p, i - 1);
|
|
|
|
#elif defined PARTITION_TYPE_HOARE
|
|
|
|
quicksort(a, p, i);
|
|
|
|
#endif
|
|
|
|
quicksort(a, i + 1, r);
|
2020-10-06 15:01:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 01:30:06 +02:00
|
|
|
uint32_t getQuicksortMedian(std::vector<uint32_t> a, int i)
|
2020-10-14 00:26:32 +02:00
|
|
|
{
|
2020-10-06 16:28:39 +02:00
|
|
|
//std::qsort(numbers); // only takes array param -> custom implementation with vector
|
2020-10-18 01:30:06 +02:00
|
|
|
quicksort(a, 0, a.size() - 1);
|
|
|
|
return a[i];
|
2020-10-06 15:01:50 +02:00
|
|
|
}
|