17 lines
399 B
Factor
17 lines
399 B
Factor
USING: locals sequences kernel math ;
|
|
IN: sorting.insertion
|
|
|
|
<PRIVATE
|
|
:: insert ( seq quot n -- )
|
|
n zero? [
|
|
n n 1- [ seq nth quot call ] bi@ >= [
|
|
n n 1- seq exchange
|
|
seq quot n 1- insert
|
|
] unless
|
|
] unless ; inline
|
|
PRIVATE>
|
|
|
|
: insertion-sort ( seq quot -- )
|
|
! quot is a transformation on elements
|
|
over length [ insert ] with with each ; inline
|