-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tree.h
63 lines (45 loc) · 1.66 KB
/
Tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef TREE_H
#define TREE_H
#include "Node.h"
#include <string>
using namespace std;
//Class that transforms a string to a Balanced Binary Search Tree
class Tree
{
private:
string theWord;
Node* rootPtr;
protected:
//------------------------------------------------------------
// Protected Utility Methods Section:
// Recursive helper methods for the public methods.
//------------------------------------------------------------
// Recursively deletes all nodes from the tree.
void destroyTree(Node* subTreePtr);
// Recursively searches for target value in the tree by using a
// preorder traversal.
bool containsHelper(Node* subTreePtr, const char& target) const;
void convertStrToTree();
// Recursively adds a new node to the tree in a way to
// keep the tree sorted.
Node* addHelper(Node* subTreePtr, Node* newNodePtr);
void swapper (char &x, char &y); //used in stringSort()
void stringSort(string &str); //used in convertStrToTree()
int findMidpoint(int length); //used in convertStrToTree()
public:
//------------------------------------------------------------
// Constructor and Destructor Section.
//------------------------------------------------------------
Tree();
Tree(const string& str);
virtual ~Tree();
//------------------------------------------------------------
// Public BinaryTreeInterface Methods Section.
//------------------------------------------------------------
void add(const char& newData); // Adds a node
bool contains(const char& anEntry) const;
void setWord(const string& str);
string getWord() const;
}; // end Tree
#endif
//end Tree.h