segmentation fault
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
Trie& Trie::operator+= (const string & word){
TrieNode * curr = root;
for (int i = 0; i < word.length(); i++) {
if (curr->left == NULL){
TrieNode*node=new TrieNode();
node -> data = word[i];
node->left = NULL;
node->right = NULL;
curr->left = node;
curr = curr->left;
}
else{
curr = curr->left;
while (curr->data != word[i]) {
if (curr->right == NULL){
TrieNode*node=new TrieNode();
node -> data = word[i];
node->right = NULL;
node->left = NULL;
curr->right = node;
}
curr = curr->right;
}
}
}
return *this;
}
|
Someone please help!! This function is giving me segmentation fault!! I'm trying to insert a word.
Use the debugger, it'll show you where you get the segfault, we can't do much without the full implementation of your class.
This is my struct:
1 2 3 4 5 6
|
struct TrieNode {
int data;
bool end;
TrieNode *left;
TrieNode *right;
};
|
Last edited on
Topic archived. No new replies allowed.