<br><br><div><span class="gmail_quote">On 7/30/07, <b class="gmail_sendername">Zeng Fucen</b> &lt;<a href="mailto:zengfucen@gmail.com">zengfucen@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m a scheme novice,<br><br>I want to travel a binary tree, how to ? (depth first)<br><br>Thanks for your tips , first!<br><br>I define a tree like this:&nbsp;&nbsp;(1 (2 4 5) (3 6 7))<br><br>_________________________________________________
<br>&nbsp;&nbsp;For list-related administrative tasks:<br>&nbsp;&nbsp;<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br></blockquote></div><br>The syntax for defining a list of any sort is either:
<br>(list ...)<br>&#39;(...) &lt;- What&#39;s inside will NOT be evaluated.<br><br>Hans gave a nice example:<br><br>&quot;(1 (2 (4 () ()) (5 () ())) (3 (6 () ()) (7 () ()))&quot;<br><br>You don&#39;t *need* it, but it makes more sense that way.
<br><br>(define (travel-tree l)<br>&nbsp;&nbsp; (cond ((null? l) ())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((list? l) (travel-tree (car l)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (t (travel-tree (cdr l))))<br><br>The above method _should_ work, but I can&#39;t guarantee it because I have my own problems.
<br>I assume that it&#39;ll be tail-recursive, considering that it will not evaluate the rest of the condition if it succeeds.<br><br>All in all, I hope this helps.<br>