小编Lok*_*okk的帖子

Haskell Inserstion排序计数

我的问题是转向:

 iSort :: Ord a => [a] -> [a]
 iSort [] = []
 iSort (x:xs) = ins x (iSort xs)

 ins x [] = [x]
 ins x (y:ys)
   | x <= y    = x : y : ys
   | otherwise = y : ins x ys
Run Code Online (Sandbox Code Playgroud)

在一个跟踪它进行比较的次数的解决方案中,这里是我需要生成的代码的框架:

 iSortCount :: Ord a => [a] -> (Integer, [a])
 iSortCount [] = ...
 iSortCount (x:xs) = ...

 insCount x (k, [])     = ... 
 insCount x (k, (y:ys)) -- Count the times when it …
Run Code Online (Sandbox Code Playgroud)

sorting monads haskell counting

3
推荐指数
1
解决办法
1486
查看次数

标签 统计

counting ×1

haskell ×1

monads ×1

sorting ×1