Sorting algorithms/Strand sort: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (→{{header|REXX}}: Refurbished) |
(Realize in F#) |
||
Line 466: | Line 466: | ||
After: {18,51,340,346,417,502,551,746,903,940}</pre> |
After: {18,51,340,346,417,502,551,746,903,940}</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
<syntaxhighlight lang="fsharp"> |
|||
// Strand sort. Nigel Galloway: August 18th., 2023 |
|||
let fN g=let mutable n=g in fun g->if n>g then false else n<-g; true |
|||
let fI n=let fN=fN(List.head n) in List.partition fN n |
|||
let rec fG n g=[match n,g with [],g|g,[]->yield! g |
|||
|n::gn,i::ng when n<i->yield n; yield! fG gn g |
|||
|n,g::ng->yield g; yield! fG n ng] |
|||
let rec fL n g=match n with []->g |_->let n,i=fI n in fL i (n::g) |
|||
let sort n=fL n []|>List.fold(fun n g->fG n g)[] |
|||
printfn "%A" (sort ["one";"two";"three";"four"]);; |
|||
printfn "%A" (sort [2;3;1;5;11;7;5]) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
["four"; "one"; "three"; "two"] |
|||
[1; 2; 3; 5; 5; 7; 11] |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
<syntaxhighlight lang="go">package main |
<syntaxhighlight lang="go">package main |