Open andrealorenzon opened 5 years ago
Node search(Node root, T key)
{
// Base Cases: root is null or key is present at root
if (root == NULL || root->key == key)
return root;
// Key is greater than root's key
if (root->key < key)
return search(root->right, key);
// Key is smaller than root's key
return search(root->left, key);
}
Accepts a key as input
Returns a shared_ptr to the searched key Node if the key is present in the tree, Returns nullpointer otherwise