Problem 63 Solutions

Solution 1

completeTree : a -> Int -> Tree a
completeTree v n =
    case n of 
        0 ->
            Empty

        _ ->
            Node v (addNode v (2) n) (addNode v (3) n)


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

`

Back to problem

results matching ""

    No results matching ""