Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct TrieNode {
- char val;
- bool word_end;
- TrieNode* kids[26] = {0};
- TrieNode(char Val ): val(Val),word_end(false){
- }
- };
- class Trie {
- TrieNode* root;
- void add(string word) {
- TrieNode* cur=root;
- for (int j=0; j<word.length();j++) {
- int i=word[j]-'a';
- if (cur->kids[i]==nullptr) {
- cur->kids[i] = new TrieNode(word[j]);
- }
- cur=cur->kids[i];
- if(j+1==word.length())
- cur->word_end=true;
- }
- }
- };
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement