%% df([[a,[b,c]],[d,e]],List). df(Tree,List) :- df(Tree,[],List), !. df([Left,Right],List1,List3) :- df(Left,List1,List2),df(Right,List2,List3). df(Item,List1,List2) :- append(List1,[Item],List2). %% bf([[a,[b,c]],[d,e]],List) bf(Tree,List) :- bf(Tree,[],List), !. bf([Left,Right],List1,List2) :- bf(Left,List1,List3), bf(Right,List2,List3). bf(Item,List1,List2) :- append(List1,[Item],List2). /**, append( append(List3,[List4],List2), append(List %%append(List3,[List4],List2) %% append(List3,List5,List2).**/ %%bf2([a,[a,[a,[a]]]] bf2([L,R],List) :- bf2(R,List2), bf2(L,List1), reverse(List2,List3), reverse( append(List1,List2,List),!, bf2(A,A). solve_breadthfirst(Node, Path) :- breadthfirst([[Node]], RevPath), reverse(RevPath, Path). breadthfirst([[Node|Path]|_], [Node|Path]) :- goal(Node). breadthfirst([Path|Paths], SolutionPath) :- expand_breadthfirst(Path, ExpPaths), append(Paths, ExpPaths, NewPaths), breadthfirst(NewPaths, SolutionPath). goal(b).