title: Tree preorder traversal in Prolog
body: <p>Tree traversal refers to the process of visiting each node in a tree data structure in a systematic way. The preorder traversal in the following image</p>
  
  <p><a href="http://en.wikipedia.org/wiki/File%3aSorted_binary_tree.svg" rel="nofollow">Sorted_binary_tree</a></p>
  
  <p>returns F, B, A, D, C, E, G, I, H (root, left, right).  This is the Prolog code:</p>
  
  <pre><code>preorder(tree(X,L,R),Xs) :-
      preorder(L,Ls),
      preorder(R,Rs),
      append([X|Ls],Rs,Xs).
  preorder(void,[]).
  </code></pre>
  
  <p>I would write a prolog program that returns</p>
  
  <p>F, B, A, F,B,D, C,F,B,D, E,F, G, I, H</p>
  
  <p>that is, the paths of the tree. Any suggestions?</p>