]> gitweb.factorcode.org Git - factor.git/blob - basis/sorting/insertion/insertion.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / 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