sorting.bubble: loop up to last changed index.

db4
John Benediktsson 2014-11-29 18:36:46 -08:00
parent 0d3fc9d976
commit d21ce7aa1c
1 changed files with 3 additions and 3 deletions

View File

@ -9,10 +9,10 @@ IN: sorting.bubble
<PRIVATE <PRIVATE
:: (bubble-sort!) ( seq quot: ( obj1 obj2 -- <=> ) -- ) :: (bubble-sort!) ( seq quot: ( obj1 obj2 -- <=> ) -- )
seq length [ seq length 1 - [
1 - f over [0,b) [| i | f over [0,b) [| i |
i i 1 + [ seq nth-unsafe ] bi@ 2dup quot call +gt+ = i i 1 + [ seq nth-unsafe ] bi@ 2dup quot call +gt+ =
[ i 1 + i [ seq set-nth-unsafe ] bi-curry@ bi* drop t ] [ i 1 + i [ seq set-nth-unsafe ] bi-curry@ bi* 2drop i t ]
[ 2drop ] if [ 2drop ] if
] each ] each
] loop drop ; inline ] loop drop ; inline