-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrieNode.cpp
59 lines (52 loc) · 1.11 KB
/
TrieNode.cpp
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
#include "TrieNode.h"
#include <iostream>
using namespace std;
TrieNode::TrieNode(){ //+=
endOfWord = false;
for (int i = 0; i < CHAR_SIZE-1; i++)
{
next[i] = nullptr;
}
}
int TrieNode::numChildren(){
int tempChildren = 0;
for (int i = 0; i < CHAR_SIZE-1; i++)
{
if (next[i])
{
//cout << "Has a child at " << i;
tempChildren++;
}
}
}
bool TrieNode::hasChild(int toCheck){
if (next[toCheck])
return true;
else
return false;
}
bool TrieNode::hasChildren(){
for (int i = 0; i < CHAR_SIZE-1; i++)
{
if (next[i])
{
//cout << "Has a child at " << next[i] << endl;
return true;
}
}
return false;
} // Returns true if the TrieNode has any children
// (i.e. any of the A-Z pointers are not nullptr)
void TrieNode::setAsLeaf(){
next[26] = new TrieNode();
}
void TrieNode::setAsInteriorNode(){
delete next[26];
next[26] = nullptr;
}
bool TrieNode::isLeaf(){
if (next[26])
return true;
else
return false;
}