]> gitweb.factorcode.org Git - factor.git/blob - extra/sorting/insertion/insertion.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / sorting / insertion / insertion.factor
1 USING: locals sequences kernel math ;
2 IN: sorting.insertion
3
4 <PRIVATE
5 :: insert ( seq quot: ( elt -- elt' ) n -- )
6     n zero? [
7         n n 1- [ seq nth quot call ] bi@ >= [
8             n n 1- seq exchange
9             seq quot n 1- insert
10         ] unless
11     ] unless ; inline recursive
12 PRIVATE>
13
14 : insertion-sort ( seq quot -- )
15     ! quot is a transformation on elements
16     over length [ insert ] with with each ; inline