Setup output to file and sort methods (not implemented)
This commit is contained in:
parent
7e8873fd1a
commit
d48e023234
BIN
bin/main.out
BIN
bin/main.out
Binary file not shown.
BIN
build/main.o
BIN
build/main.o
Binary file not shown.
BIN
include/.sorts.h.swp
Normal file
BIN
include/.sorts.h.swp
Normal file
Binary file not shown.
@ -4,18 +4,27 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
enum SortType {INSERTION = 0, MERGE, HEAP};
|
||||||
|
|
||||||
class Sorter
|
class Sorter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::vector<std::string> wordList;
|
int lineCount;
|
||||||
|
std::vector<std::string> originalWordList;
|
||||||
|
std::vector<std::string> newWordList;
|
||||||
|
SortType currentType;
|
||||||
public:
|
public:
|
||||||
void SetFileName(std::string newName);
|
Sorter(std::string newFilename);
|
||||||
std::string GetFileName(void);
|
std::string GetFilename(void);
|
||||||
|
void SetFilename(std::string newName);
|
||||||
void SetWordList(void);
|
void SetWordList(void);
|
||||||
|
void RunSorts(void);
|
||||||
|
void OutputResult(void);
|
||||||
|
void PrintToFile(std::string outputFilename);
|
||||||
void InsertionSort(void);
|
void InsertionSort(void);
|
||||||
void MergeSort(void);
|
void MergeSort(void);
|
||||||
void HeapSort(void);
|
void HeapSort(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
BIN
src/.sorts.cpp.swp
Normal file
BIN
src/.sorts.cpp.swp
Normal file
Binary file not shown.
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Sorter newSort;
|
Sorter newSort(argv[1]);
|
||||||
newSort.SetFileName(argv[1]);
|
newSort.RunSorts();
|
||||||
newSort.SetWordList();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,20 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void Sorter::SetFileName(std::string newName)
|
Sorter::Sorter(std::string newFilename)
|
||||||
|
{
|
||||||
|
lineCount = 0;
|
||||||
|
currentType = INSERTION;
|
||||||
|
SetFilename(newFilename);
|
||||||
|
SetWordList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sorter::SetFilename(std::string newName)
|
||||||
{
|
{
|
||||||
this->filename = newName;
|
this->filename = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Sorter::GetFileName(void)
|
std::string Sorter::GetFilename(void)
|
||||||
{
|
{
|
||||||
return this->filename;
|
return this->filename;
|
||||||
}
|
}
|
||||||
@ -24,10 +32,63 @@ void Sorter::SetWordList(void)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
while (getline(file, bufferStr))
|
while (getline(file, bufferStr))
|
||||||
wordList.push_back(bufferStr);
|
{
|
||||||
|
originalWordList.push_back(bufferStr);
|
||||||
|
lineCount++;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
void Sorter::InsertionSort(void)
|
void Sorter::InsertionSort(void)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
@ -41,4 +102,4 @@ void Sorter::MergeSort(void)
|
|||||||
void Sorter::HeapSort(void)
|
void Sorter::HeapSort(void)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
0
test/OUTPUT/.keep
Normal file
0
test/OUTPUT/.keep
Normal file
15000
test/OUTPUT/HS0K.txt
Normal file
15000
test/OUTPUT/HS0K.txt
Normal file
File diff suppressed because it is too large
Load Diff
15000
test/OUTPUT/IS0K.txt
Normal file
15000
test/OUTPUT/IS0K.txt
Normal file
File diff suppressed because it is too large
Load Diff
15000
test/OUTPUT/MS0K.txt
Normal file
15000
test/OUTPUT/MS0K.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user