Created
May 30, 2020 01:44
-
-
Save Se7soz/44ee93f4aae87eb8b087dc089ca54b66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TrieNode { | |
public: | |
void insert(const string& word, int i) { | |
if (i >= word.size()) { | |
return; | |
} | |
if (children[word[i]] == NULL) { | |
children[word[i]] = new TrieNode(); | |
} | |
children[word[i]]->insert(word, i+1); | |
if (i == word.size()-1) { | |
children[word[i]]->endOfWord = true; | |
} | |
} | |
TrieNode* search(const string& word, int i) { | |
if (i == word.size() || children[word[i]] == NULL) { | |
return NULL; | |
} | |
if (i == word.size()-1) { | |
return children[word[i]]; | |
} | |
return children[word[i]]->search(word, i+1); | |
} | |
bool endOfWord; | |
TrieNode* children[512]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment