Anonymous user
Sorting Algorithms/Circle Sort: Difference between revisions
→{{header|Haskell}}: Updated Haskell code
(added Haskell implementation) |
(→{{header|Haskell}}: Updated Haskell code) |
||
Line 985:
It also uses the Writer monad to track whether or not there have been swaps.
<lang haskell>
import Data.Bool (bool)
circleSort :: Ord a => [a] -> [a]
circleSort xs =
where
(_,ls,rs) <- go xs xs▼
go
go
go
halve d
halve d (y:ys) [_]
where s = y <= head ys
| bool (<=) (<) d x y = (Any d ,(ys,x:ls,y:rs))
| otherwise = (Any (not d),(ys,y:ls,x:rs))</lang>
{{out}}
Line 1,026 ⟶ 1,016:
[-1,0,1,2,3,4,5,6,7,8,11,12,13,14]
</pre>
=={{header|J}}==
|