Created
November 14, 2018 14:22
-
-
Save bkyrlach/e3a878143224d2e5d0eb783a3fba59ff to your computer and use it in GitHub Desktop.
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 Tree where | |
| data Tree a = | |
| Leaf | |
| | Branch (Tree a) a (Tree a) | |
| flatten Leaf = [] | |
| flatten (Branch l x r) = (flatten l) ++ [x] ++ (flatten r) | |
| insertOrdered Leaf y = Branch Leaf y Leaf | |
| insertOrdered (Branch l x r) y = case (y < x) of | |
| True -> Branch (insertOrdered l y) x r | |
| False -> Branch l x (insertOrdered r y) | |
| treeSort = foldl Leaf insertOrdered |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment