Tree path in a List of Lists
问题 I want to build a predicate (Prolog) that takes a tree and returns a list of lists and each list is a tree path. The tree is defined as tree(Root,LeftTree,RightTree). Do you have any suggestions, please? 回答1: This is quite unusual (it is more common to ask for example for a relation between a tree and a flat list of all its nodes, for which DCGs are a good fit), maybe like this: tree_list(nil, []). tree_list(tree(Node,Left,Right), [Lefts,Node,Rights]) :- tree_list(Left, Lefts), tree_list