[plt-scheme] Re: Help: I want to travel a binary tree?
Yes, it works!
my code:
--------------------
(define travsal (lambda (tree)
(cond
((null? tree) ())
(#t (append (travsal (car tree)) (cons (cadr tree)
(travsal (caddr tree))))))))
(define tree1 '(((() 4 ()) 2 (() 5 ())) 1 ((() 6 ()) 3 (() 7 ()))))
(display tree1)
(newline)
(travsal tree1)
-------------------
the result is :
(((() 4 ()) 2 (() 5 ())) 1 ((() 6 ()) 3 (() 7 ())))
(4 2 5 1 6 3 7)
On 8月1日, 下午6时46分, Chris Uzdavinis <ch... at atdesk.com> wrote:
> Zeng Fucen <zengfu... at gmail.com> writes:
> > Thanks Joshua!
> > I'm used to using C/C++ , and I agree with you .
> > These days , when I started FP , every function use recursion !
> > That makes things a little interesing.
>
> If you can write a C++ template meta-program to traverse a tree, then
> it's a cakewalk in Scheme. (And much prettier!)
>
> --
> Chris
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme