插入排序
insert :: Int -> [Int] -> [Int] insert x [] = [x] insert x (y:ys) | x < y = x:y:ys | otherwise = y : insert x ys insertSort :: [Int] -> [Int] insertSort [] = [] insertSort (x:xs) = insert x (insertSort xs)
归并排序
merge :: [Int] -> [Int] -> [Int] merge xs [] = xs merge [] ys = ys merge (x:xs) (y:ys) | x > y = y:merge (x:xs) ys | otherwise = x:merge xs (y:ys) mergeSort :: [Int] -> [Int] mergeSort [] = [] mergeSort [x] = [x] mergeSort list = merge (mergeSort a) (mergeSort b) where (a,b) = splitAt (div (length list)2) list
快速排序
quickSort :: [Int] -> [Int] quickSort [] = [] quickSort (x:xs) = quickSort [a|a<-xs,a<=x] ++ [x] ++ quickSort [a|a<-xs,a>x]
</
到此这篇haskell函数式程序设计 pdf_excel 排序函数的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/haskellbc/1904.html