-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinarySearchTree.h
50 lines (38 loc) · 1.43 KB
/
BinarySearchTree.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
#pragma once
#include <string>
#include <vector>
#include "Node.h"
class BinarySearchTree
{
public:
// **Constructors and destructors**
// Creates an empty binary tree
BinarySearchTree();
// Creates a binary search tree with an initial word to store
BinarySearchTree(std::string word);
// Creates a binary search tree by copying an existing tree
BinarySearchTree(const BinarySearchTree &rhs);
// Creates a binary search tree from a collection of existing words
BinarySearchTree(const std::vector<std::string> &words);
// Destroys (cleans up) the tree
~BinarySearchTree();
// **Methods that can be called on a BinarySearchTree object**
// Adds a word to the tree
void insert(std::string word);
// Checks if a word is in the tree
bool exists(std::string word) const;
// Creates a string representing the tree in alphabetical order
std::string inorder() const;
// Creates a string representing the tree in pre-order
std::string preorder() const;
// Creates a string representing the tree in post-order
std::string postorder() const;
// **Operator overloads**
// Inserts a new word into the binary tree
BinarySearchTree& operator+(std::string word);
// Copy assignment operator
BinarySearchTree& operator=(const BinarySearchTree &rhs);
private:
//instance variables
Node *root = nullptr; // Pointer to the root Node of the tree
};