This code
if (x < binTree<T>::root->data)
is checking against root
, note currentNode, so the test will never change. So if your x
value is less than root->data
you will keep trying to recurse through currentNode->left
until you either hit a leaf (if you are lucky) or you hit a node with a NULL left pointer, in which case you will recurse with currentNode
as NULL, which will cause a segfault in leaf
when it tries to check for currentNode->left
You should be checking against currentNode
. You should also be returning the return value of your search
recursive calls