插入排序
insert::Ord a => a -> [a] -> [a]
insert x [] = [x]
insert x (y:ys) | x < y = x:y:ys
| otherwise = y:(insert x ys)
isort::Ord a => [a] -> [a]
isort [] = []
isort (x:xs) = insert x (isort xs)
使用示例:
> isort [5,4,3,2,1]
结果:
[1,2,3,4,5]