Problem 61b Solutions

Solution 1

getLeaves : Tree a -> List a
getLeaves tree =
    case tree of
        Empty ->
            []

        Node v left right ->
            if left == Empty && right == Empty then
                [v]
            else
                getLeaves left ++ getLeaves right

Back to problem

results matching ""

    No results matching ""