This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
data Tree a = EmptyTree | Node a (Tree a) (Tree a) | |
(<<) EmptyTree value = Node value EmptyTree EmptyTree | |
(<<) (Node value left right) newValue = if newValue < value | |
then Node value (left << newValue) right | |
else Node value left (right << newValue) | |
toArray EmptyTree = [] | |
toArray (Node value left right) = toArray left ++ value : toArray right | |
printTree :: (Show t) => Tree t -> IO () | |
printTree tree = mapM_ print (toArray tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment