sorting.insertion: skip the zero'th element.
parent
72efd16074
commit
00bd0c52e7
|
@ -2,6 +2,7 @@ USING: kernel locals math sequences sequences.private ;
|
||||||
IN: sorting.insertion
|
IN: sorting.insertion
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
:: insert ( ... seq quot: ( ... elt -- ... elt' ) n -- ... )
|
:: insert ( ... seq quot: ( ... elt -- ... elt' ) n -- ... )
|
||||||
n zero? [
|
n zero? [
|
||||||
n n 1 - [ seq nth-unsafe quot call ] bi@ >= [
|
n n 1 - [ seq nth-unsafe quot call ] bi@ >= [
|
||||||
|
@ -9,8 +10,9 @@ IN: sorting.insertion
|
||||||
seq quot n 1 - insert
|
seq quot n 1 - insert
|
||||||
] unless
|
] unless
|
||||||
] unless ; inline recursive
|
] unless ; inline recursive
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: insertion-sort ( ... seq quot: ( ... elt -- ... elt' ) -- ... )
|
: insertion-sort ( ... seq quot: ( ... elt -- ... elt' ) -- ... )
|
||||||
! quot is a transformation on elements
|
! quot is a transformation on elements
|
||||||
over length [ insert ] with with each-integer ; inline
|
over length [ insert ] with with 1 -rot (each-integer) ; inline
|
||||||
|
|
Loading…
Reference in New Issue