我的问题是转向:
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)