Can somebody please explain what is wrong with the below code for binary search insertion?It gives segmentation fault when I try to insert 2nd element.
node * insert(node * root, int value)
{
if(root == NULL){
node *newnode = (node *)malloc(sizeof(node));
newnode->data = value;
newnode->left = NULL;
newnode->right = NULL;
root = newnode;
}
else{
if(root->data > value)
insert(root->left, value);
if(root->data < value)
insert(root->right, value);
}
return root;
}
int main(){
node* root = NULL;
root = insert(root, 5);
root = insert(root, 10);
}