Unformatted text preview: Postorder: Look at the children before the node. ;;;;; In file cs61a/lectures/2.2/print.scm (define (postorder tree) (cond ((null? tree) ()) (else (postorder (leftbranch tree)) (postorder (rightbranch 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; (findplace berkeley worldtree) (world (united states) california berkeley) If a place isnt found, findplace 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 oneelement list containing just the place. Otherwise, we look at each child of the root, and see if weis a oneelement list containing just the place....
View
Full Document
 Spring '10
 Harvey,B
 Tree traversal, Nested set model, root node

Click to edit the document details