Problem 63 Solutions

Solution 1

completeTree : a -> Int -> Tree a
completeTree v n =
    if (n > 0) then
        Node v (addNode v 2 n) (addNode v 3 n)
    else
        Empty


addNode : a -> Int -> Int -> Tree a
addNode v idx end =
    if (idx <= end) then
        Node v (addNode v (idx * 2) end) (addNode v (idx * 2 + 1) end)
    else
        Empty

`

Back to problem

results matching ""

    No results matching ""