// Inserts a word into the trie. void insert(string word) { TrieNode* itr = root; for (int i = 0; i < word.length(); ++i) { itr = itr->addNode(word[i]); } if (itr != root) { itr->setWordEnd(); } }
void addWordToTrie(string& word) { TrieNode* cur = root_; for (char& c : word) cur = cur->addTrieNode(c); cur->setWordEnd(); }