Ladies_Man

#SORT__Дерево Сортировки

Jan 22nd, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Tree a = Leaf | Node (Tree a) a (Tree a)
  2.  
  3. --insert :: Ord a => a -> Tree a -> Tree a
  4.  
  5. insert x Leaf = Node Leaf x Leaf
  6.  
  7. insert x (Node t y t') | x <= y = Node (insert x t) y t'
  8. insert x (Node t y t') | x > y = Node t y (insert x t')
  9.  
  10. --flatten :: Tree a -> [a]
  11.  
  12. flatten Leaf = []
  13. flatten (Node t x t') = flatten t ++ [x] ++ flatten t'
  14.  
  15.  
  16.  
  17. --treesort :: Ord a => [a] -> [a]
  18.  
  19. treesort = flatten . foldr insert Leaf
Advertisement
Add Comment
Please, Sign In to add comment