Finished main part of RBT and BST
This commit is contained in:
+16
-4
@@ -114,6 +114,12 @@ void SortController::SetOutput(std::string filename)
|
||||
return;
|
||||
}
|
||||
|
||||
bool SortController::IsOutputSpecified(void)
|
||||
{
|
||||
return outputFile.is_open();
|
||||
}
|
||||
|
||||
|
||||
void SortController::TestInsertion(void)
|
||||
{
|
||||
newWordList = originalWordList;
|
||||
@@ -151,7 +157,7 @@ void SortController::ConstructBST(void)
|
||||
binarySearchTree.InsertWordList(&newWordList);
|
||||
auto end = std::chrono::system_clock::now();
|
||||
sortTime = end - start;
|
||||
OutputResult();
|
||||
std::cout << "BST construction took " << sortTime.count() << 's' << std::endl;
|
||||
}
|
||||
|
||||
void SortController::ConstructRBT(void)
|
||||
@@ -162,7 +168,7 @@ void SortController::ConstructRBT(void)
|
||||
newTree.InsertWordList(&newWordList);
|
||||
auto end = std::chrono::system_clock::now();
|
||||
sortTime = end - start;
|
||||
OutputResult();
|
||||
std::cout << "RBT construction took " << sortTime.count() << 's' << std::endl;
|
||||
}
|
||||
|
||||
void SortController::BSTInsert(std::string key)
|
||||
@@ -186,7 +192,10 @@ void SortController::BSTSearch(std::string key)
|
||||
void SortController::BSTInOrderTreeTraversal(std::string key)
|
||||
{
|
||||
auto start = std::chrono::system_clock::now();
|
||||
binarySearchTree.InOrderTreeTraversal(redBlackTree.GetNodeWithWord(key));
|
||||
if (IsOutputSpecified())
|
||||
binarySearchTree.InOrderTreeTraversal(binarySearchTree.GetNodeWithWord(key), &outputFile);
|
||||
else
|
||||
binarySearchTree.InOrderTreeTraversal(binarySearchTree.GetNodeWithWord(key));
|
||||
auto end = std::chrono::system_clock::now();
|
||||
sortTime = end - start;
|
||||
std::cout << "Operation took " << sortTime.count() << 's' << std::endl;
|
||||
@@ -249,7 +258,10 @@ void SortController::RBTSearch(std::string key)
|
||||
void SortController::RBTInOrderTreeTraversal(std::string key)
|
||||
{
|
||||
auto start = std::chrono::system_clock::now();
|
||||
redBlackTree.InOrderTreeTraversal(redBlackTree.GetNodeWithWord(key));
|
||||
if (IsOutputSpecified())
|
||||
redBlackTree.InOrderTreeTraversal(redBlackTree.GetNodeWithWord(key), &outputFile);
|
||||
else
|
||||
redBlackTree.InOrderTreeTraversal(redBlackTree.GetNodeWithWord(key));
|
||||
auto end = std::chrono::system_clock::now();
|
||||
sortTime = end - start;
|
||||
std::cout << "Operation took " << sortTime.count() << 's' << std::endl;
|
||||
|
||||
+2
-2
@@ -89,12 +89,12 @@ namespace tree_implementation
|
||||
}
|
||||
|
||||
// Prints tree while traversing it to a file
|
||||
void TreeInterface::InOrderTreeTraversal(std::shared_ptr<TreeNode> viewedNode, std::ofstream file)
|
||||
void TreeInterface::InOrderTreeTraversal(std::shared_ptr<TreeNode> viewedNode, std::ofstream* file)
|
||||
{
|
||||
if (viewedNode)
|
||||
{
|
||||
InOrderTreeTraversal(viewedNode->leftChild);
|
||||
file << viewedNode.get()->key << '\n';
|
||||
*file << viewedNode.get()->key << '\n';
|
||||
InOrderTreeTraversal(viewedNode->rightChild);
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user