Added user interaction with BST and RBT

This commit is contained in:
2023-03-06 21:54:40 -06:00
parent dfaa4d38a8
commit 226bf8587a
9 changed files with 640 additions and 116 deletions
+33
View File
@@ -0,0 +1,33 @@
#ifndef INTERFACE_HPP
#define INTERFACE_HPP
#include "sort_controller.hpp"
#include <string>
#include <vector>
class Interface
{
public:
SortController benchmark;
Interface(void);
void CheckArguments(int argc, char* arguments[]);
void Construction(void);
bool IsBST(void);
bool IsOnlySorting(void);
void Sort(void);
bool UserInput(void);
void BSTRequestExecution(void);
void RBTRequestExecution(void);
protected:
;
private:
int userInput;
std::string givenWord;
SortType currentType;
bool allLists, sortGiven;
void CheckRequirements(void);
void PrintHelp(void);
void PrintOptions(void);
};
#endif
+30
View File
@@ -1,7 +1,9 @@
#ifndef SORT_CONTROLLER_HPP
#define SORT_CONTROLLER_HPP
#include "trees.hpp"
#include <chrono>
#include <fstream>
#include <string>
#include <vector>
@@ -14,12 +16,40 @@ public:
void CheckArguments(int argc, char* arguments[]);
void ReadWordFile(void);
void RunBenchmarks(void);
void SetFilename(std::string name);
std::string GetFilename(void);
void SetOutput(std::string filename);
void TestInsertion(void);
void TestMerge(void);
void TestHeap(void);
void ConstructBST(void);
void ConstructRBT(void);
void BSTInsert(std::string key);
void BSTSearch(std::string key);
void BSTInOrderTreeTraversal(std::string key);
void BSTPrintParentKey(std::string key);
void BSTPrintLeftChild(std::string key);
void BSTPrintRightChild(std::string key);
void BSTPrintPathToRoot(std::string key);
void RBTInsert(std::string key);
void RBTSearch(std::string key);
void RBTInOrderTreeTraversal(std::string key);
void RBTPrintParentKey(std::string key);
void RBTPrintLeftChild(std::string key);
void RBTPrintRightChild(std::string key);
void RBTPrintPathToRoot(std::string key);
void RBTPrintColor(std::string key);
void RBTPrintParentColor(std::string key);
void RBTPrintUncleColor(std::string key);
protected:
;
private:
std::string filename;
std::ofstream outputFile;
SortType currentType;
std::string wordToLocate;
tree_implementation::BinarySearchTree binarySearchTree;
tree_implementation::RedBlackTree redBlackTree;
std::chrono::duration<double> sortTime;
std::vector<std::string> newWordList;
std::vector<std::string> originalWordList;
+6 -3
View File
@@ -1,6 +1,7 @@
#ifndef TREES_HPP
#define TREES_HPP
#include <fstream>
#include <memory>
#include <string>
#include <vector>
@@ -42,18 +43,20 @@ namespace tree_implementation
public:
TreeList tree;
TreeInterface(void);
std::shared_ptr<TreeNode> Search(std::string wordToFind);
bool IsSearchSuccessful(std::shared_ptr<TreeNode> foundNode, std::string key);
void Search(std::string key);
std::shared_ptr<TreeNode> GetNodeWithWord(std::string wordToFind);
void InOrderTreeTraversal(std::shared_ptr<TreeNode> viewedNode);
void InOrderTreeTraversal(std::shared_ptr<TreeNode> viewedNode, std::ofstream file);
void PrintParentKey(std::string key);
void PrintLeftChild(std::string key);
void PrintRightChild(std::string key);
protected:
bool IsNodeSearchSuccessful(std::shared_ptr<TreeNode> foundNode, std::string key);
virtual void Insert(std::shared_ptr<TreeNode> z);
virtual void InsertWordList(std::vector<std::string>* newWordList) = 0;
virtual void PrintPathToRoot(std::string key) = 0;
private:
std::shared_ptr<TreeNode> Search(std::shared_ptr<TreeNode> viewedNode, std::string wordToFind);
std::shared_ptr<TreeNode> GetNodeWithWord(std::shared_ptr<TreeNode> viewedNode, std::string wordToFind);
};
// Binary Search Tree operations