notes39 - Postorder: Look at the children before the node....

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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: > (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

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.

Ask a homework question - tutors are online