blob: 4613694e9d1579e89b379c6c5ec41601ce7ada98 (
plain)
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
|
#ifndef TRIE_H
#define TRIE_H
#include <iostream>
template <class T>
struct trie_node {
char c;
T* value = NULL;
trie_node<T>* next = nullptr;
trie_node<T>* child = nullptr;
trie_node (char c) : c(c) { };
trie_node (char c, trie_node<T>* next, trie_node<T>* child);
};
template <class T>
std::ostream& operator<<(std::ostream&, trie_node<T>* node);
template <class T>
struct trie {
trie_node<T>* root;
trie () : root (new trie_node<T> ('\0')) { }
int push_back (const char* key, const T&);
T& operator[] ( const char* key );
bool empty () { return this->root->child == NULL; }
};
template <class T>
std::ostream& operator<<(std::ostream&, trie<T>* trie);
#endif /* TRIE_H */
|