Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created November 14, 2018 14:22
Show Gist options
  • Select an option

  • Save bkyrlach/e3a878143224d2e5d0eb783a3fba59ff to your computer and use it in GitHub Desktop.

Select an option

Save bkyrlach/e3a878143224d2e5d0eb783a3fba59ff to your computer and use it in GitHub Desktop.
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