在 C++ 中实现 trie 需要帮助

need help in implementation of trie in c++

class node {

     public:
     node(){
       value  = 0;
       arr = new node*[26];
       for(int i =0 ; i<26;i++)
         arr[i]= NULL;
       }
      int  value;
      node ** arr ;
};
class trie {
     public:
        trie(){
           root = NULL;
        }
     node * root;
     int count;
};
int main(){
        string A[5] = {"apple, ball , bat , cat, car"};
        trie* too;
        node *p = new node();
        too->root = p; // **here**
}

这里:我有一个运行时错误..对我来说它似乎是正确的..我不知道它有什么问题。任何帮助对我都有很大用处 :) 谢谢

too 没有指向任何东西。

最简单的解决方法是删除 * 使其成为本地对象而不是指针。

int main(){
    string A[5] = {"apple, ball , bat , cat, car"};
    trie too; //<------ Fix here
    node *p = new node();
    too->root = p; // **here**
}

或者,您可以 new trie 对象。但为了您的目的,这是不必要的。