Sorting algorithms/Insertion sort: Difference between revisions
Sorting algorithms/Insertion sort (view source)
Revision as of 04:06, 27 February 2020
, 4 years agoAdd Factor
(Added a V implementation) |
(Add Factor) |
||
Line 1,446:
collection |> isort []
</lang>
=={{header|Factor}}==
{{trans|Haskell}}
<lang factor>USING: kernel prettyprint sorting.extras sequences ;
: insertion-sort ( seq -- sorted-seq )
<reversed> V{ } clone [ swap insort-left! ] reduce ;
{ 6 8 5 9 3 2 1 4 7 } insertion-sort .</lang>
{{out}}
<pre>
{ 1 2 3 4 5 6 7 8 9 }
</pre>
But note that Factor already comes with an <code>insertion-sort</code> in the <code>sorting.insertion</code> vocabulary that is likely faster and more robust. See its implementation [https://docs.factorcode.org/content/word-insertion-sort%2Csorting.insertion.html here].
=={{header|Forth}}==
|