BST seems to fully work, moving on to RBT
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum SortType {INSERTION = 0, MERGE, HEAP};
|
||||
enum SortType {INSERTION = 0, MERGE, HEAP, BST, RBT, LAST};
|
||||
|
||||
class SortController
|
||||
{
|
||||
@@ -19,11 +19,12 @@ protected:
|
||||
private:
|
||||
std::string filename;
|
||||
SortType currentType;
|
||||
std::string wordToLocate;
|
||||
std::chrono::duration<double> sortTime;
|
||||
std::vector<std::string> newWordList;
|
||||
std::vector<std::string> originalWordList;
|
||||
int lineCount;
|
||||
bool defaultFile, defaultOnly, fileGiven, allLists, sortGiven;
|
||||
bool defaultFile, defaultOnly, fileGiven, allLists, sortGiven, locate;
|
||||
void Benchmarking(void);
|
||||
void BenchmarkingAll(void);
|
||||
void OutputResult(void);
|
||||
|
||||
+16
-17
@@ -13,20 +13,17 @@ namespace tree_implementation
|
||||
{
|
||||
std::string key;
|
||||
std::string color;
|
||||
std::unique_ptr<TreeNode> leftChild;
|
||||
std::unique_ptr<TreeNode> rightChild;
|
||||
std::unique_ptr<TreeNode> parent;
|
||||
std::shared_ptr<TreeNode> leftChild;
|
||||
std::shared_ptr<TreeNode> rightChild;
|
||||
std::shared_ptr<TreeNode> parent;
|
||||
TreeNode(std::string word);
|
||||
~TreeNode(void);
|
||||
TreeNode(const TreeNode& rhs);
|
||||
TreeNode& operator=(const TreeNode& rhs);
|
||||
};
|
||||
|
||||
// General list for Tree
|
||||
class TreeList
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<TreeNode> head;
|
||||
std::shared_ptr<TreeNode> head;
|
||||
TreeList(void);
|
||||
void InsertAtStart(std::string word);
|
||||
void InsertAtEnd(std::string word);
|
||||
@@ -45,18 +42,18 @@ namespace tree_implementation
|
||||
public:
|
||||
TreeList tree;
|
||||
TreeInterface(void);
|
||||
TreeNode* Search(std::string wordToFind);
|
||||
bool IsSearchSuccessful(std::unique_ptr<TreeNode> foundNode);
|
||||
void InOrderTreeTraversal(std::unique_ptr<TreeNode> viewedNode);
|
||||
std::shared_ptr<TreeNode> Search(std::string wordToFind);
|
||||
bool IsSearchSuccessful(std::shared_ptr<TreeNode> foundNode, std::string key);
|
||||
void InOrderTreeTraversal(std::shared_ptr<TreeNode> viewedNode);
|
||||
void PrintParentKey(std::string key);
|
||||
void PrintLeftChild(std::string key);
|
||||
void PrintRightChild(std::string key);
|
||||
protected:
|
||||
virtual void Insert(std::unique_ptr<TreeNode> z);
|
||||
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:
|
||||
TreeNode* Insert(std::unique_ptr<TreeNode> root, std::unique_ptr<TreeNode> newNode);
|
||||
TreeNode* Search(std::unique_ptr<TreeNode>* viewedNode, std::string wordToFind);
|
||||
std::shared_ptr<TreeNode> Search(std::shared_ptr<TreeNode> viewedNode, std::string wordToFind);
|
||||
};
|
||||
|
||||
// Binary Search Tree operations
|
||||
@@ -64,6 +61,7 @@ namespace tree_implementation
|
||||
{
|
||||
public:
|
||||
void Insert(std::string keyToInsert);
|
||||
void InsertWordList(std::vector<std::string>* newWordList);
|
||||
void PrintPathToRoot(std::string key);
|
||||
protected:
|
||||
;
|
||||
@@ -76,6 +74,7 @@ namespace tree_implementation
|
||||
{
|
||||
public:
|
||||
void Insert(std::string keyToInsert);
|
||||
void InsertWordList(std::vector<std::string>* newWordList);
|
||||
void PrintPathToRoot(std::string key);
|
||||
void PrintColor(std::string key);
|
||||
void PrintParentColor(std::string key);
|
||||
@@ -83,10 +82,10 @@ namespace tree_implementation
|
||||
protected:
|
||||
;
|
||||
private:
|
||||
void InsertFixup(std::unique_ptr<TreeNode> z);
|
||||
std::unique_ptr<TreeNode> GetUncleNode(std::unique_ptr<TreeNode> startNode);
|
||||
void LeftRotate(std::unique_ptr<TreeNode> x);
|
||||
void RightRotate(std::unique_ptr<TreeNode> x);
|
||||
void InsertFixup(std::shared_ptr<TreeNode> z);
|
||||
std::shared_ptr<TreeNode> GetUncleNode(std::shared_ptr<TreeNode> startNode);
|
||||
void LeftRotate(std::shared_ptr<TreeNode> x);
|
||||
void RightRotate(std::shared_ptr<TreeNode> x);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user