Problem 72

Collect the nodes of a multiway tree in depth-first order.

Solution

type MTree a
    = MNode a (List (MTree a))


toList : MTree a -> List a
toList (MNode v list) =
    if List.length list == 0 then
        [ v ]
    else
        (List.concatMap (\x -> toList x) list) ++ [ v ]

Back to problem

results matching ""

    No results matching ""