2023-01-12 13:32:19 -06:00
|
|
|
#include "sorts.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-01-16 16:11:40 -06:00
|
|
|
Sorter::Sorter(std::string newFilename)
|
|
|
|
{
|
|
|
|
lineCount = 0;
|
|
|
|
currentType = INSERTION;
|
|
|
|
SetFilename(newFilename);
|
|
|
|
SetWordList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sorter::SetFilename(std::string newName)
|
2023-01-12 13:32:19 -06:00
|
|
|
{
|
|
|
|
this->filename = newName;
|
|
|
|
}
|
|
|
|
|
2023-01-16 16:11:40 -06:00
|
|
|
std::string Sorter::GetFilename(void)
|
2023-01-12 13:32:19 -06:00
|
|
|
{
|
|
|
|
return this->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sorter::SetWordList(void)
|
|
|
|
{
|
|
|
|
std::string bufferStr;
|
|
|
|
std::ifstream file(this->filename);
|
|
|
|
if (!file.is_open())
|
|
|
|
{
|
|
|
|
std::cout << "Failed opening file\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
while (getline(file, bufferStr))
|
2023-01-16 16:11:40 -06:00
|
|
|
{
|
|
|
|
originalWordList.push_back(bufferStr);
|
|
|
|
lineCount++;
|
|
|
|
}
|
2023-01-12 13:32:19 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-16 16:11:40 -06:00
|
|
|
void Sorter::RunSorts(void)
|
|
|
|
{
|
|
|
|
newWordList = originalWordList;
|
|
|
|
InsertionSort();
|
|
|
|
OutputResult();
|
|
|
|
currentType = MERGE;
|
|
|
|
newWordList = originalWordList;
|
|
|
|
MergeSort();
|
|
|
|
OutputResult();
|
|
|
|
currentType = HEAP;
|
|
|
|
newWordList = originalWordList;
|
|
|
|
HeapSort();
|
|
|
|
OutputResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sorter::OutputResult(void)
|
|
|
|
{
|
|
|
|
switch(currentType)
|
|
|
|
{
|
|
|
|
case INSERTION:
|
|
|
|
PrintToFile("IS");
|
|
|
|
break;
|
|
|
|
case MERGE:
|
|
|
|
PrintToFile("MS");
|
|
|
|
break;
|
|
|
|
case HEAP:
|
|
|
|
PrintToFile("HS");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sorter::PrintToFile(std::string outputFilename)
|
|
|
|
{
|
|
|
|
std::string outputPath = "test/OUTPUT/";
|
|
|
|
outputPath += outputFilename;
|
|
|
|
outputPath += std::to_string(lineCount % 1000);
|
|
|
|
outputPath += "K.txt";
|
|
|
|
std::ofstream file(outputPath);
|
|
|
|
if (!file.is_open())
|
|
|
|
{
|
|
|
|
std::cout << "Failed opening file\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < lineCount; i++)
|
|
|
|
file << newWordList[i] << '\n';
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:32:19 -06:00
|
|
|
void Sorter::InsertionSort(void)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sorter::MergeSort(void)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sorter::HeapSort(void)
|
|
|
|
{
|
|
|
|
;
|
2023-01-16 16:11:40 -06:00
|
|
|
}
|