Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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