Why do I need to define new Trienode in the following code as the new TrieNode();
when I do it as new TrieNode;
it gives segmentation fault. Is there a default constructor for struct datatype that’s important to call here, if so what does it do?
struct TrieNode
{
struct TrieNode *children[ALPHABET_SIZE];
bool isLeaf;
};
void insert(struct TrieNode *root, string key)
{
for(int i=0; i<key.size(); i++)
{
if(root->children[key[i]-'a'] ==NULL) root->children[key[i]-'a'] = new TrieNode();
root = root->children[key[i]-'a'];
}
root->isLeaf = true;
}