I am using Recursion to search an element in my Binary Search Tree but my code stops working if the element is not present in the BST.
void tree::searching(node *root,int key)
{
if(root->key==key||root==NULL)
{
cout<<"Congratulation Element found in the BST"<<"\n";
return;
} else {
if(key<root->key)
{
searching(root->left,key);
} else {
searching(root->right,key);
}
}
}
rootis wrong.