Reputation: 81
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
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