// Returns if there is any word in the trie // that starts with the given prefix. bool startsWith(string prefix) { TrieNode* itr = root; for (int i = 0; itr != NULL && i < prefix.length(); ++i) { itr = itr->locateCh(prefix[i]); } return (itr != NULL); }
// Returns if the word is in the trie. bool search(string word) { TrieNode* itr = root; for (int i = 0; itr != NULL && i < word.length(); ++i) { itr = itr->locateCh(word[i]); } return (itr != NULL && itr->isWordEnd()); }