私は実装のトライです。これは単語の終わりに達すると定義を出力します。定義の文字列を使用しています。定義を割り当てるとコードがクラッシュします文字列Trieの構造体の文字列によるプログラムのクラッシュ
#include <bits/stdc++.h>
#define ALPHABET_SIZE 26
#define CHAR_TO_INDEX(c) ((int)c - (int)'0')
using namespace std;
typedef struct trienode{
string definition; //For Definition of the word
bool isLeaf;
struct trienode *children[ALPHABET_SIZE];
}node;
node* getnode()
{
int i;
node *t=new node();
t->isLeaf=false;
for(i=0;i<26;i++)
{
t->children[i]=NULL;
}
return t;
}
void insert(node *root,string s)
{
node *crawler=root;
int level,index,length=s.length();
for(level=0;level<length;level++)
{
index= CHAR_TO_INDEX(s[level]);
if(crawler->children[index]==NULL)
{
crawler->children[index]=getnode();
}
crawler=crawler->children[index];
}
crawler->definition= "Definition of" + s; //Here is the code crashing,when I am assigning the definition
crawler->isLeaf=true;
}
[mcve]を投稿してください。 – PaulMcKenzie
大文字ではない文字列を渡している可能性があります。 – sameerkn