Esempio n. 1
0
 // 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);
 }
Esempio n. 2
0
 // 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());
 }