Separate approx. MoM and exact with quickselect
This commit is contained in:
parent
6357dd605b
commit
16f10c0937
22
main.cpp
22
main.cpp
@ -13,7 +13,7 @@
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// read test values from input file
|
||||
std::string type = "init\t\t\t\t\t";
|
||||
std::string type = "init\t\t\t\t\t\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::vector<uint32_t > numbers = readFromFile("testdata");
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
@ -32,14 +32,14 @@ int main(int argc, char** argv)
|
||||
uint32_t* array = new uint32_t[numbers.size()];
|
||||
|
||||
// vollständige Sortierung mit Quicksort und Ausgabe des mittleren Elements
|
||||
type = "quicksort median\t\t\t";
|
||||
type = "quicksort median\t\t\t\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::cout << type << getQuicksortMedian(numbers, idxMed) << std::endl;
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// comparison of std::qsort and std::sort
|
||||
// using std quicksort for array
|
||||
type = "array quicksort\t\t\t\t";
|
||||
type = "array quicksort\t\t\t\t\t";
|
||||
std::copy(numbers.begin(), numbers.end(), array);
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::qsort(array, numbers.size(), sizeof(uint32_t), compare);
|
||||
@ -47,7 +47,7 @@ int main(int argc, char** argv)
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// comparison "quick" sort with std::sort (introsort)
|
||||
type = "array std sort\t\t\t\t";
|
||||
type = "array std sort\t\t\t\t\t";
|
||||
std::copy(numbers.begin(), numbers.end(), array);
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::sort(array, array + numbers.size());
|
||||
@ -55,25 +55,31 @@ int main(int argc, char** argv)
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// vorgestellter Randomzized - Select rekursiv implementiert
|
||||
type = "randomized select\t\t\t";
|
||||
type = "randomized select\t\t\t\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::cout << type << getRandomizedSelectMedian(numbers, 0, numbers.size() - 1, idxMed + 1) << std::endl;
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// ein weiterer Median - Algorithmus aus der Literatur - implemented with std::vector
|
||||
type = "vector median of medians\t\t";
|
||||
type = "vector median of medians only (approximative)\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::cout << type << numbers[pivot(numbers, 0, numbers.size() - 1)] << std::endl;
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// ein weiterer Median - Algorithmus aus der Literatur - implemented with std::vector
|
||||
type = "vector median of medians + quickselect (exact)\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::cout << type << getMedianOfMedians(numbers, 0, numbers.size() - 1, idxMed) << std::endl;
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// noch ein ein weiterer Median - Algorithmus weil wir so cool sind
|
||||
type = "wirth kth element\t\t\t";
|
||||
type = "wirth kth element\t\t\t\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::cout << type << getWirthKthSmallest(numbers, idxMed) << std::endl;
|
||||
Timing::getInstance()->stopRecord(type);
|
||||
|
||||
// Verwendung des C++ STL function templates nth_element
|
||||
type = "nth element\t\t\t\t";
|
||||
type = "nth element\t\t\t\t\t";
|
||||
Timing::getInstance()->startRecord(type);
|
||||
std::nth_element(numbers.begin(), numbers.begin() + idxMed, numbers.end());
|
||||
std::cout << type << numbers[idxMed] << std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user