Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. module Task where
  2.  
  3. data Tree a = Branch a (Tree a) (Tree a) | Leaf
  4. deriving (Show)
  5.  
  6. constructTree :: [Int] -> Tree Int
  7. constructTree [] = Leaf
  8. constructTree [x] = Branch x Leaf Leaf
  9. constructTree (x : xs) =
  10. let splitA [] _ _ = ([],[])
  11. splitA [x] acc n = if x > n then (acc, [x]) else ([x], acc)
  12. splitA (x : xs) acc n = if x > n then (acc, x : xs) else splitA xs (acc ++ [x]) n
  13. (a,b) = splitA xs [] x
  14. in Branch x (constructTree a) (constructTree b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement