Problem 61a Solutions

Solution 1

countLeaves : Tree a -> Int
countLeaves tree =
    case tree of
        Empty ->
            0

        Node v left right ->
            if left == Empty && right == Empty then
                1
            else
                (countLeaves left) + (countLeaves right)

Back to problem

results matching ""

    No results matching ""