Repository navigation
Expand file tree
/
Copy pathtrienode.cpp
More file actions
59 lines (53 loc) · 1.66 KB
/
Copy pathtrienode.cpp
File metadata and controls
59 lines (53 loc) · 1.66 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
/******************************************************************
Title: trienode.cpp
Author: Erin Williams
Date Created: 4/30/2017
Class: Spring 2017, CSCI 235-04, Mon & Wed 7:00pm-8:15pm
Professor: Aarsh Vora
Purpose: Assignment #3
Description: TrieNode implementation file
*******************************************************************/
#include <map>
#include <string>
#include "trienode.h"
namespace triewilliams {
TrieNode::TrieNode() : wordEnd_(false) {
std::map<char, TrieNode*> map;
children_ = map;
}
TrieNode* TrieNode::findChild(char letter) {
//Get iterator to node containing letter
std::map<char, TrieNode*>::iterator it = children_.find(letter);
//If found in current case:
if(it != children_.end()) {
return it->second;
}
//If not found in current case, look for opposite case
else {
//If uppercase char, look for lowercase version
if(isupper(letter)) {
std::map<char, TrieNode*>::iterator LCit = children_.find(tolower(letter));
//Found lowercase version
if(LCit != children_.end()) {
return LCit->second;
}
//Not found, letter not in map
else {
return NULL;
}
}
//If lowercase char, look for uppercase version
else {
std::map<char, TrieNode*>::iterator UCit = children_.find(toupper(letter));
//Found lowercase version
if(UCit != children_.end()) {
return UCit->second;
}
//Not found, char not in map
else {
return NULL;
}
}
}
}
} //triewilliams