Inserting words into a binary search tree
I'm writing a program where I have to randomly choose 100 words from an array and put it into a binary search tree. I got the array working the random selection working but putting the words into the tree is not working for me. I've got the code to compile but get an error when I try to run it.
Can somebody please check this code and give me some feedback as to why the program won't run?
This is most of the code relating to the tree:
Code:
/*create tree*/
void createtree(NODE *root)
{
root=(NODE *)malloc(sizeof(NODE));
root->left=NULL;
root->right=NULL;
}
/*insert words into the tree*/
void insert(NODE *node, char *word)
{
if(node=NULL){
node=(NODE *) malloc(sizeof(NODE));
strcpy(node->data, word);
node->left=NULL;
node->right=NULL;
}
else{
if(strcmp(word, node->data)<0)
insert(node->left, word);
else if(strcmp(word, node->data)>0)
insert(node->right, word);
}
}
and this is the line i use to call the function insert
Code:
insert(root, words[randnum].word);