I am making a basic binary search tree and its operations.
Why isn't my insert working?
It is not taking in the values and the root that I am sending from the main does not get associated to the values I insert.
void insert(struct bst* root, int val)
{
if (root == NULL)
{
struct bst* temp = malloc(sizeof(struct bst));
temp->val = val;
temp->left = NULL;
temp->right = NULL;
root = temp;
}
else
{
if (root->val > val)
{
insert(root->left,val);
}
else if (root->val < val)
{
insert(root->right,val);
}
else
{
printf("alredy exits");
}
}
}