【问题标题】:need help in implementation of trie in c++在 C++ 中实现 trie 时需要帮助
【发布时间】:2015-11-17 22:40:37
【问题描述】:
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**
}

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

【问题讨论】:

    标签: c++ data-structures trie


    【解决方案1】:

    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 对象。但出于您的目的,这是不必要的。

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多