-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstring.cpp
More file actions
30 lines (26 loc) · 779 Bytes
/
substring.cpp
File metadata and controls
30 lines (26 loc) · 779 Bytes
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
#include <iostream>
#include <map>
#include <string>
#include <stack>
struct trie_node_t {
typedef std::map<char, trie_node_t *> child_node_t;
child_node_t m_childMap;
trie_node_t() :m_childMap(std::map<char, trie_node_t*>()) {}
void insert( std::string& word ) {
trie_node_t *pNode = this;
for ( std::string::const_iterator itr = word.begin(); itr != word.end(); ++itr) {
char letter = *itr;
if ( pNode->m_childMap.find(letter) == pNode->m_childMap.end()){
pNode->m_childMap[letter] = new trie_node_t();
}
pNode = pNode->m_childMap[letter];
}
}
void print() {
}
};
int main () {
trie_node_t trie;
trie.insert(std::string("aab"));
trie.print();
}