Unformatted text preview: Postorder: Look at the children before the node. ;;;;; In file cs61a/lectures/2.2/print.scm (define (post-order tree) (cond ((null? tree) ()) (else (post-order (left-branch tree)) (post-order (right-branch tree)) (print (entry tree)) ))) For a tree of arithmetic operations, preorder traversal looks like Lisp; inorder traversal looks like conventional arithmetic notation; and postorder traversal is the HP calculator reverse Polish notation. Path finding As an example of a somewhat more complicated tree program, suppose we want to look up a place (e.g., a city) in the world tree, and find the path from the root node to that place: &gt; (find-place berkeley world-tree) (world (united states) california berkeley) If a place isnt found, find-place will return the empty list. To find a place within some tree, first we see if the place is the datum of the root node. If so, the answer is a one-element list containing just the place. Otherwise, we look at each child of the root, and see if weis a one-element list containing just the place....
View Full Document
- Spring '10
- Tree traversal, Nested set model, root node