-
Notifications
You must be signed in to change notification settings - Fork 1
/
BinaryDictionary.h
53 lines (38 loc) · 1.18 KB
/
BinaryDictionary.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
//
// Author: Varick Erickson
// Date: 2/18/2021
//
#ifndef TREET_H
#define TREET_H
#include <string>
#include <fstream>
using namespace std;
class BadDigit{};
class BinaryDictionary {
public:
BinaryDictionary();
~BinaryDictionary();
BinaryDictionary(const BinaryDictionary& otherDict); // copy constructor
void SaveDictionary(string filename);
BinaryDictionary& operator=(const BinaryDictionary& otherDict);
void Add(string binValue); // Add value to the tree
bool Contains(string value); // Determines if value is in the tree
void MakeEmpty(); // Remove all binary words
int Size(); // Number of binary values
private:
struct Node {
Node* zero = nullptr;
Node* one = nullptr;
bool isNum = false;
};
Node* root;
int numValues;
// This helper function is used by the copy constructor and the
// assignment operator.
void copyOther(const BinaryDictionary& otherDict);
// Used for de-constructor
void DestroyHelper(Node* node);
void CopyHelper(Node*& thisTree, Node* otherTree);
void SaveDictionaryHelper(Node* node, string currPrefix, ofstream& outFile);
};
#endif //TREET_H