30 lines
1.1 KiB
C++
Raw Normal View History

2020-10-06 14:34:16 +02:00
#include <iostream>
#include <algorithm> // std::nth_element
2020-10-06 14:34:16 +02:00
#include "fileHandler.h"
#include "Timing.h"
#include "MedianQuicksort.h"
2020-10-06 14:34:16 +02:00
int main(int argc, char** argv) {
Timing::getInstance()->startRecord("init");
std::vector<size_t> numbers = readFromFile("testdata");
std::cout << "read " << numbers.size() << " values" << std::endl;
2020-10-06 14:34:16 +02:00
Timing::getInstance()->stopRecord("init");
// vollst<73>ndige Sortierung mit Quicksort und Ausgabe des mittleren Elements
Timing::getInstance()->startRecord("quicksort");
std::cout << "quicksort median: " << getMedian(numbers) << std::endl;
Timing::getInstance()->stopRecord("quicksort");
// Verwendung des C++ STL function templates nth_element
Timing::getInstance()->startRecord("nth element");
std::nth_element(numbers.begin(), numbers.begin() + numbers.size() / 2, numbers.end());
size_t idxMed = numbers.size() / 2;
if (idxMed - (int)idxMed > 0) idxMed++;
std::cout << "nth element: " << numbers[idxMed] << std::endl;
Timing::getInstance()->stopRecord("nth element");
2020-10-06 14:34:16 +02:00
//Timing::getInstance()->getResults();
Timing::getInstance()->print();
return 0;
}