I have some code
tree1(tree(1,
tree(2,
tree(3,nil,nil),
tree(4,nil,nil)),
tree(5,
tree(6,nil,nil),
tree(7,nil,nil))
)
).
rbt_count_nodes(e,0):-!.
rbt_count_nodes(t(_,L,R),N):-
rbt_count_nodes(L,NL),
rbt_count_nodes(R,NR),
N=NL+NR+1.
?-tree1(T),rbt_count_nodes(T,N),write(N).
But goal always return No. Why ?
should become
and
should become
(
(=)/2is used to perform unification,(is)/2to perform arithmetic).and
should become
After those three edits it should be fine, though I cannot test so I might be proven wrong.