-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboggleutil.h
More file actions
65 lines (53 loc) · 1.64 KB
/
Copy pathboggleutil.h
File metadata and controls
65 lines (53 loc) · 1.64 KB
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
64
65
#ifndef BOGGLEUTIL_H
#define BOGGLEUTIL_H
#include <string>
using std::string;
class TSTNode
{
public:
TSTNode *left;
TSTNode *right;
TSTNode *mid;
bool end; // Signifies whether this node holds the last char in a word in the Lexicon
const char data;
TSTNode(const char &val) : left(NULL), right(NULL), mid(NULL), end(false), data(val) {}
};
class TST
{
public:
TSTNode *root;
// Constructor
TST() : root(NULL) {}
/**
* Tells us whether the passed in string exists in the Lexicon or is a prefix of
* a word in the Lexicon
* @method TST::find
* @param data Check if data is a prefix of any word in the TST
* @param current Pointer to the current TSTNode in the recursion
* @return 2: The word was a prefix and a valid word in the Lexicon
* 1: The word was a prefix but not a valid word in the Lexicon
* 0: The word was not a prefix or a valid word in the Lexicon
*/
char find(string data, TSTNode *current);
/**
* Recursively inserts a new string into the TST
* @method TST::insert
* @param data The string to be inserted
* @param current The current node in the traversal
*/
void insert(string data, TSTNode *¤t);
// Destructor delegates to clear() method
~TST()
{
clear(root);
root = NULL;
}
private:
/**
* Helper method for the destructor. Recursively deletes all nodes in the TST.
* @method TST::clear
* @param current current node in the traversal
*/
void clear(TSTNode *current);
};
#endif // BOGGLEUTIL_H