Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
(Added a V implementation)
(Add Factor)
Line 1,446: Line 1,446:
collection |> isort []
collection |> isort []
</lang>
</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}}==
=={{header|Forth}}==