i am trying to insert the charachter in to ternary search tree, please help me out with this segmentation fault ?? here is what i am doing to inser in to trie,on running this i am getting segmentation fault(core dumped ) please help me out why this is so ??
int main(int argc ,char* agrv[])
{
TSTNode *root;
char *str;
cin >> str;
InsertTST(root,str);
DisplayTST(root);
return 0;
}
TSTNode* InsertTST(TSTNode *root, char *str)
{
if(root== NULL){
TSTNode *root = (TSTNode *)malloc(sizeof(TSTNode *));
root->left = NULL;
root->right = NULL;
root->eq = NULL;
root->is_end_of_str = 0;
return root;
}
if(root->data < *str)
InsertTST(root->right, str);
else if (root->data == *str){
if(*(str+1) != '\0')
InsertTST(root->eq, str+1);
else
root->is_end_of_str = 1;
}
else
InsertTST(root->left, str);
return root;
}