diff --git a/src/sort_controller.cpp b/src/sort_controller.cpp index 059db1e..65e5b34 100644 --- a/src/sort_controller.cpp +++ b/src/sort_controller.cpp @@ -19,6 +19,48 @@ SortController::SortController() sortGiven = 0; } +// Checks for command line arguments +void SortController::CheckArguments(int argc, char* arguments[]) +{ + std::string tempStr; + for (int i = 0; i < argc; i++) + { + tempStr = arguments[i]; + if ((tempStr == "-a") || (tempStr == "--all")) + { + defaultOnly = 0; + allLists = 1; + } + if ((tempStr == "-f") || (tempStr == "--filename")) + { + filename = arguments[i + 1]; + defaultOnly = 0; + fileGiven = 1; + } + if ((tempStr == "-d") || (tempStr == "--default")) + { + filename = "test/PERM/perm15K.txt"; + defaultFile = 1; + } + if ((tempStr == "-s") || (tempStr == "--sort-type")) + { + sortGiven = 1; + tempStr = arguments[i + 1]; + if (tempStr == "insertion") + currentType = INSERTION; + if (tempStr == "merge") + currentType = MERGE; + if (tempStr == "heap") + currentType = HEAP; + if (tempStr == "all") + sortGiven = 0; + } + } + if (defaultOnly) + filename = "test/PERM/perm15K.txt"; + return; +} + // Sets word list found in file into vector void SortController::ReadWordFile(void) { @@ -50,23 +92,6 @@ void SortController::RunBenchmarks(void) return; } -// Sorts all default files if allLists is set -void SortController::BenchmarkingAll(void) -{ - int fileCount = 10; - std::string newFilename; - for (int i = 1; i <= fileCount; i++) - { - lineCount = 0; - newFilename = "test/PERM/perm"; - newFilename += std::to_string(15*i); - newFilename += "K.txt"; - filename = newFilename; - ReadWordFile(); - Benchmarking(); - originalWordList.clear(); - } -} // Function for starting sort functions void SortController::Benchmarking(void) @@ -106,6 +131,25 @@ void SortController::Benchmarking(void) } } +// Sorts all default files if allLists is set +void SortController::BenchmarkingAll(void) +{ + int fileCount = 10; + std::string newFilename; + for (int i = 1; i <= fileCount; i++) + { + lineCount = 0; + newFilename = "test/PERM/perm"; + newFilename += std::to_string(15*i); + newFilename += "K.txt"; + filename = newFilename; + ReadWordFile(); + Benchmarking(); + originalWordList.clear(); + } +} + + // Main function for printing results void SortController::OutputResult(void) { @@ -153,45 +197,3 @@ void SortController::WriteOutputToFile(std::string outputFilename) file << newWordList[i] << '\n'; file.close(); } - -// Checks for command line arguments -void SortController::CheckArguments(int argc, char* arguments[]) -{ - std::string tempStr; - for (int i = 0; i < argc; i++) - { - tempStr = arguments[i]; - if ((tempStr == "-a") || (tempStr == "--all")) - { - defaultOnly = 0; - allLists = 1; - } - if ((tempStr == "-f") || (tempStr == "--filename")) - { - filename = arguments[i + 1]; - defaultOnly = 0; - fileGiven = 1; - } - if ((tempStr == "-d") || (tempStr == "--default")) - { - filename = "test/PERM/perm15K.txt"; - defaultFile = 1; - } - if ((tempStr == "-s") || (tempStr == "--sort-type")) - { - sortGiven = 1; - tempStr = arguments[i + 1]; - if (tempStr == "insertion") - currentType = INSERTION; - if (tempStr == "merge") - currentType = MERGE; - if (tempStr == "heap") - currentType = HEAP; - if (tempStr == "all") - sortGiven = 0; - } - } - if (defaultOnly) - filename = "test/PERM/perm15K.txt"; - return; -} \ No newline at end of file