Depth of a tree (Haskell)

前端 未结 3 699
灰色年华
灰色年华 2021-01-23 16:25

I\'m trying to figure out how to calculate the depth of a general tree in Haskell. I can figure out the solution for simple binary trees, but not for general trees with any numb

3条回答
  •  长发绾君心
    2021-01-23 16:39

    A few pointers:

    Take a look at the map function which allows you to apply a function to each element in a list. In your case you want to apply depth to each Tree a in the list of children.

    After you get that part you have to find the max depth in the list. Do a google search for "haskell max of list" and you'll find what you need.

提交回复
热议问题