How can I search for an element in a binary tree that is not a bst?
This is an example of how my tree looks
1
/ \
2 3
/ \ / \
4 5 6 7
This is what I'm doing:
treeNode * find(treeNode *T, int x) {
if(T == NULL) return NULL;
if(x == T -> element) {
return T;
}
find(T -> left, x);
find(T -> right, x);
return NULL;
}
The problem is that the recursion does not stop when the if is satisfied
find, you should do something with the return values. That's how you detect a successful search, no?NULLunless it is already the searched for element.