Created
May 26, 2014 14:48
-
-
Save loosechainsaw/fe765c864ad3c2dd52cb to your computer and use it in GitHub Desktop.
Lame Binary Tree in Haskell
This file contains hidden or 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
module Main where | |
data List a = Nil | Cons a (List a) | |
deriving (Show) | |
data Tree a = Empty | Node a (Tree a) (Tree a) | |
deriving (Show) | |
append :: (Ord a) => Tree a -> a -> Tree a | |
append Empty a = Node a (Empty) (Empty) | |
append (Node item left right) a | |
| a < item = (Node item (append left a) right) | |
| a > item = (Node item left (append right a)) | |
| otherwise = (Node item left right) | |
btree = Node 100 Empty Empty | |
btree2 = append btree 50 | |
btree3 = append btree2 30 | |
btree4 = append btree3 80 | |
main = print $ btree4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment