user2239690
user2239690

Reputation: 81

How to replace the nodes of a tree by the respective depths - OCaml

I am new to OCaml, and am trying to figure out a way to replace all nodes in a tree by their depth. I think I'll have to construct a new tree. Can anyone help?

Upvotes: 1

Views: 321

Answers (1)

gasche
gasche

Reputation: 31459

Yes, you have to build a new tree. You should try to define a (recursive) function that takes two parameters, a subtree and the depth of this subtree, and returns the subtree where all nodes have been replaced by their depth. Then you can get what you want by applying this function on the whole tree with depth 0.

Upvotes: 2

Related Questions