-1

I need help in racket pl

Using this BINTREE definition, write a (higher-order) function called treemap that takes in a numeric function f and a binary tree, and returns a tree with the same shape but using f(n) for values in its leaves. For example, here is a test case:

(test (tree-map add1 (Node (Leaf 1) (Node (Leaf 2) (Leaf 3))))

=> (Node (Leaf 2) (Node (Leaf 3) (Leaf 4))))

What I did is:

[Node BINTREE BINTREE]

[Leaf Number])

> >

(define(treemap f tree)

[(Leaf Number) f(Number)]

[(Node tree BTREE) treemap(Node)]))

learn
  • 13
  • 1
  • 3

1 Answers1

0

Replace

[(Leaf Number) f(Number)] 

with

[(Leaf Number) (Leaf f(number))]

and the Node will return a node and active the functions on its arguments.

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28
Tal
  • 29
  • 3