class Trie {public: struct Node{ bool is_end; Node *son[26]; Node(){ is_end = false; for(int i=0;i<26;i++) son[i] = NULL; } }* root; /** Initialize your data structure here. */ Trie() { root = new Node(); } /** Inserts a word into the trie. */ void insert(string word) { Node*p = root; for(auto c:word){ int v = c-'a'; if(p->son[v]==NULL) p->son[v] = new Node(); p = p->son[v]; } p->is_end= true; } /** Returns if the word is in the trie. */ bool search(string word) { Node*p = root; for(auto c:word){ int v = c-'a'; if(p->son[v]==NULL) return false; p = p->son[v]; } if(!p->is_end) return false; return true; } /** Returns if there is any word in the trie that starts with the given prefix. */ bool startsWith(string prefix) { Node*p = root; for(auto c:prefix){ int v = c-'a'; if(p->son[v]==NULL) return false; p = p->son[v]; } return true; }};/** * Your Trie object will be instantiated and called as such: * Trie* obj = new Trie(); * obj->insert(word); * bool param_2 = obj->search(word); * bool param_3 = obj->startsWith(prefix); */