Advertisement
karlicoss

inssort

Jul 24th, 2011
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sortedInsert :: (Ord a) => [a] -> a -> [a]
  2. sortedInsert [] a = [a]
  3. sortedInsert l@(x: xs) a
  4.     | a > x = [x] ++ sortedInsert xs a
  5.     | otherwise = [a] ++ l
  6.  
  7. insSort :: (Ord a) => [a] -> [a]
  8. insSort l = foldl sortedInsert [] l
  9.  
  10. main = do
  11.     let us = [23, 9, 8, 3, 1, 23, 435]
  12.     let st = insSort us
  13.     putStrLn $ show st
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement