Write n analogous function (maptree f t)
that returns a tree made by applying the function f
to each entry of the binary tree t
. (Just like map) Since the tree is a data abstraction, only the followings are allowed to operate on trees:(entry t) (right-branch t) (left-branch t) (make=tree entry left right), and (empty-tree? t)
. You may use the predefined constant the-empty-tree
.
Example:
(define tree
(make-tree 10 (make-tree 5 the-empty-tree the-empty-tree)
(make-tree 12 the-empty-tree the-empty-tree)))
tree
(10 (5 () ())(12 () ()))
(maptree square tree)
(100 (25 () ())(144 () ()))