File: Insort.hs

package info (click to toggle)
hat 2.02-12
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,296 kB
  • ctags: 668
  • sloc: haskell: 64,394; ansic: 6,112; sh: 888; makefile: 451
file content (10 lines) | stat: -rw-r--r-- 253 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
sort :: Ord a => [a] -> [a]
sort []     = []
sort (x:xs) = insert x (sort xs)

insert :: Ord a => a -> [a] -> [a]
insert x []     = [x]
insert x (y:ys) = if x <= y then x : y : ys
                  else y : insert x ys

main = putStrLn (sort "program")