To produce the list of leaves of a tree. Note that in-order traversal, pre-order traversal and post-order traversal all produce the same flattened list of leaves, so it doesn't matter which we pick.
(In Lisp, Scheme is a little different):
(defun flatten (l)
(cond
((null l) nil)
((atom l) (list l))
(t (append (flatten (car l)) (flatten (cdr l))))))
Note that this is not particularly
efficient; in fact, the repeated use of
append is
terrible!