Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Task where
- data Tree a = Branch a (Tree a) (Tree a) | Leaf
- deriving (Show)
- constructTree :: [Int] -> Tree Int
- constructTree [] = Leaf
- constructTree [x] = Branch x Leaf Leaf
- constructTree (x : xs) =
- let splitA [] _ _ = ([],[])
- splitA [x] acc n = if x > n then (acc, [x]) else ([x], acc)
- splitA (x : xs) acc n = if x > n then (acc, x : xs) else splitA xs (acc ++ [x]) n
- (a,b) = splitA xs [] x
- in Branch x (constructTree a) (constructTree b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement