Your problem sounds to me like this:
given binary tree
=> flatten the right most branch
=> reverse the flatten list
=> make it a binary tree
For example.
t(a,t(b, t(c)) =>
=> [a, b, c]
=> [c, b, a]
=> t(c, t(b, t(a))
Am I missing something ? Anyway, I hope this help.
Kuniaki Mukai
> On Jun 3, 2017, at 17:45, Juan <
juaan...@gmail.com> wrote:
>
> Hi !
>
> I want to know how to reverse the nodes in a binary tree like this :
>
> [[[[[],1,[]],5,[]],
> 7,
> [[],3,[[],4,[]]]],
> 6,
> [[[],10,[]],
> 8,
> [[[],9,[]],11,[[],2,[]]]]]
>
>
> I can only use this ABN representation as lists and the following constructors and selectors of
> the abstract data type.
>
> empty([]).
> root([_,N,_], N).
> hi([HI,_,_],HI). %left son
> hd([_,_,HD],HD). %right son
> maketree(R,HI,HD,[HI,R,HD}).
>
>
> I want to know how could I make a swap predicate like this
> swap(A4,B).
>
> that working like this:
> ?- swap(A4,B).
> B=[[[[[],2,[]],11,[[],9,[]]],8,[[],10,[]]],6,[[[[],4,[]],3,[]],7,[[],5,[[],1,[]]]]]
>
> Any clues ?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
swi-prolog+...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/swi-prolog.
> For more options, visit
https://groups.google.com/d/optout.