-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrieNode.h
More file actions
64 lines (51 loc) · 1.95 KB
/
TrieNode.h
File metadata and controls
64 lines (51 loc) · 1.95 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
//
// Created by araze on 12/17/2022.
//
#ifndef WORDHUNTSOLVER_TRIENODE_H
#define WORDHUNTSOLVER_TRIENODE_H
#include <string>
const size_t NUMBER_LETTERS = 26;
class TrieNode
{
private:
TrieNode *children[NUMBER_LETTERS];
char letter;
bool endOfWord;
public:
//The constructor. Takes a character for the node, and a bool
//indicating whether it represents the end of a word. Note, there is no
//default ctor.
TrieNode(char c, bool b);
// Copy Constructor
// pre: Class object, a TrieNode, exists
// post: Object is initialized to be a copy of the parameter
TrieNode(const TrieNode& rhs);
// Class Destructor
// Destroys a TrieNode
// pre: Class object exists
// post: Class object does not exist
~TrieNode();
// Assignment operator
// Assigns a TrieNode to another
// pre: both class objects exist
// post: this class object gets assigned a copy of the parameter class
// object
const TrieNode& operator=(const TrieNode& rhs);
//Insert str starting with the given TrieNode. Create new TrieNodes
//as needed and be sure to set the boolean flag on the last node to
//true
// pre: TrieNode and Trie exist, string is provided
// post: string is inserted
void insert(const std::string& str);
//Returns true if str is in the sub-Trie starting at the given TrieNode,
//else returns false
// pre: TrieNode and Trie exist, string exists
// post: returns true if the string is a word in the subTrie, false otherwise
bool isWord(const std::string& str) const;
//Returns true if pre is a prefix in the sub-Trie starting at the given TrieNode,
//else returns false
// pre: TrieNode and Trie exist, string exists
// post: returns true if the string is a prefix in the subTrie, false otherwise
bool isPrefix(const std::string& pre) const;
};
#endif //WORDHUNTSOLVER_TRIENODE_H