Good morning,
I would like to know how I could exchange all the nodes in a binary tree in prolog , so that
If we have a tree this way:
[[[[[],1,[]],5,[]],
7,
[[],3,[[],4,[]]]],
6,
[[[],10,[]],
8,
[[[],9,[]],11,[[],2,[]]]]]
I can only use following constructors and selectors of the data abstract type.
vacio([]).
raiz([_,N,_], N).
hi([HI,_,_],HI).
hd([_,_,HD],HD).
hazarbol(R,HI,HD,[HI,R,HD}).
So how can I define a predicate that the left child exchanges for the right child at all levels so that intercambia(A4,B).
B=[[[[[],2,[]],11,[[],9,[]]],8,[[],10,[]]],6,[[[[],4,[]],3,[]],7,[[],5,[[],1,[]]]]]
Thanks