I am trying to write the rules for a predicate in Prolog that will see if a particular member (E) is in a given tree. The tree is not BST, it's like an unsorted binary tree. I can't figure out what is wrong with the logic in the code below.
treeMember(E, node(X, _, _)).
treeMember(E, node(X, L, _)) :-
treeMember(E, L).
treeMember(E, node(X, _, R)) :-
treeMember(E, R).
The given example query is
?-treeMember(3,node(1, node(2, node(3,nil,nil),node(4,nil,nil)), node(5,nil,nil))).
and that should give a '''true''', which the code does but it'll always give a true even when the (E) in question is not part of the tree. May I please have some pointers?