I am trying to create a program which which takes a list of words as an input, and sorts them into a binary tree, in order to allow them to be found, e.g. like a dictionary. This is what I have done so far, but am getting a segmentation error with newEl -> el = input;
I know this is because it is trying to point to a NULL el, when the tree is first created, but i'm not sure what the best way to improve my code would be. Anyone have any ideas? Thanks.
struct node *tra(struct node * start, Type input) {
struct node * thisNode = start;
if (thisNode == NULL)
Type current = thisNode -> el;
if (strcmp(input, current) > 0)
return tra(thisNode -> right, input);
else if (strcmp(input, current) < 0)
return tra(thisNode -> left, input);
else
return thisNode;
}
}
Ta insert(Type input, Ta ta) {
if ((find(input, ta)) == FALSE) {
newEl -> el = input;
}
return ta;
}
Boolean find(Type input, Ta ta) {
if (tra(ta -> head, input) == NULL)
return FALSE;
}