CS 6520 HW 4
Here's a data definition:
; A num-tree is either
; - num
; - (make-tree num num-tree num-tree)
(define-struct tree (v l r))
- Implement inflate-tree, which produces a tree by adding one to every number in a given tree.
- Implement grow-tree, which replaces every leaf num in the tree with (make-tree num 0 0).
- Abstract inflate-tree and grow-tree to produce a more general tree-mapping function, map2-tree. Unlike map for lists, map2-tree needs two function arguments.
- Implement sum-tree, which sums all of the numbers in a tree.
- Generalize map2-tree and sum-tree to produce fold-tree.
- Generalize the num-tree data definition to X-tree and provide new contracts for map2-tree and fold-tree that are as general as possible.
Last update: Friday, February 6th, 2004mflatt@cs.utah.edu |