Structure for Binary Search Tree (BST) nodes:
struct node {
int data;
node * left;
node * right;
}
Search Algorithm
// Check if a value exists in the tree
bool BSTSearch(node * current, int value)
{
if (current->data == value)
{
return true;
}
else if (current->data < value)
{
if (current->left == NULL)
{
return false;
}
else
{
return BSTSearch(current->left, value);
}
}
else if (current->data > value)
{
if (current->right == NULL)
{
return false;
}
else
{
return BSTSearch(current->right, value);
}
}
}