Adapt Wirth to data type change

This commit is contained in:
karl 2020-10-17 00:45:08 +02:00
parent be69fb41be
commit 90347e06a3
2 changed files with 7 additions and 7 deletions

12
Wirth.h
View File

@ -2,15 +2,15 @@
// http://ndevilla.free.fr/median/median/index.html // http://ndevilla.free.fr/median/median/index.html
size_t getWirthKthSmallest(std::vector<size_t> a, size_t k) uint32_t getWirthKthSmallest(std::vector<uint32_t> a, uint32_t k)
{ {
size_t l = 0; uint32_t l = 0;
size_t m = a.size() - 1; uint32_t m = a.size() - 1;
while (l < m) { while (l < m) {
size_t x = a[k]; uint32_t x = a[k];
size_t i = l; uint32_t i = l;
size_t j = m; uint32_t j = m;
do { do {
while (a[i] < x) i++; while (a[i] < x) i++;

View File

@ -78,7 +78,7 @@ int main(int argc, char** argv)
Timing::getInstance()->stopRecord("array median of medians");*/ Timing::getInstance()->stopRecord("array median of medians");*/
// noch ein ein weiterer Median - Algorithmus weil wir so cool sind // noch ein ein weiterer Median - Algorithmus weil wir so cool sind
std::vector<size_t> numbers_wirth(numbers); // Copy because wirth works in-place std::vector<uint32_t> numbers_wirth(numbers); // Copy because wirth works in-place
Timing::getInstance()->startRecord("wirth"); Timing::getInstance()->startRecord("wirth");
std::cout << "wirth kth element: " << getWirthKthSmallest(numbers_wirth, idxMed) << std::endl; std::cout << "wirth kth element: " << getWirthKthSmallest(numbers_wirth, idxMed) << std::endl;
Timing::getInstance()->stopRecord("wirth"); Timing::getInstance()->stopRecord("wirth");