Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

So, this works in Haskell

Name: Anonymous 2008-02-18 5:34

replaceMin :: Tree Int -> Tree Int
replaceMin t = let (t', m) = rpMin (t, m) in t'

rpMin :: (Tree Int, Int) -> (Tree Int, Int)
rpMin (Leaf a, m) = (Leaf m, a)
rpMin (Branch l r, m) = let (l', ml) = rpMin (l, m)
                            (r', mr) = rpMin (r, m)
                   in (Branch l' r', ml `min` mr)

And replaces every Leaf in the tree with the minimum value in the tree. All in one pass.

What other Voodoo magic can that dog do?

Name: Anonymous 2008-02-19 2:59

>>28
Please optimise with interrobangs.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List