Good morning, I am a beginner in Prolog and I am studying treatment of lists and trees. One question that I have is how can I add the nodes of a tree in binary principle. For example:
The trees are represented as a list as follows:
[[[[],1,[]],5,[[],4,[]]],7,[[],6,[]]]
Using a predicate like pej sumanodos (tree, S) must return the sum of nodes pej
?-sumanodos( [[[[],1,[]],5,[[],4,[]]],7,[[],6,[]]],S)
S=23
I can only use the following abstract type constructors and selectors:
nil([]).
leftnode([LN,_,_],LN)
root([_,RT,_],RT)
rightnode([_,_,RN],RN)
tree(RT,LN,RN,[LN,RT,RN])
I am particularly interested in the explanation, thank you very much in advance!