I don't really get, why you overwrite root->left
or root->right
. I think your search()
function should look like this:
BST *search(BST *root, int value)
{
if (root == NULL)
return NULL;
if (value == root->value)
return root;
if (value < root->value)
return search(root->left, value);
if (value > root->value)
return search(root->right, value);
return NULL; /* not actually reached */
}