[plt-scheme] Help: I want to travel a binary tree?
On Jul 30, 2007, at 4:20 AM, Zeng Fucen wrote:
> I'm a scheme novice,
>
> I want to travel a binary tree, how to ? (depth first)
>
> Thanks for your tips , first!
>
> I define a tree like this: (1 (2 4 5) (3 6 7))
If your collection of trees contains just this one S-expression,
which looks like that as a tree:
+-----------+------------ ...
| |
1 +------+------+
| | |
2 4 5
then your search result is '(1 2 4 5 3 6 7)
So I'd say the proper function definition is
(define (depth-first-traversal-of the-one-tree-that-is-my-possible-
input)
'(1 2 4 5 3 6 7))
Hope this helps. -- Matthias