This preview shows page 1. Sign up to view the full content.
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
This note was uploaded on 02/17/2010 for the course COMPUTER S 26275 taught by Professor Harvey,b during the Spring '10 term at University of California, Berkeley.
 Spring '10
 Harvey,B

Click to edit the document details