1 ! Copyright (C) 2014 John Benediktsson
2 ! See https://factorcode.org/license.txt for BSD license
4 USING: kernel math math.order ranges sequences
11 :: (bubble-sort-with!) ( seq quot: ( obj1 obj2 -- <=> ) -- )
14 i i 1 + [ seq nth-unsafe ] bi@ 2dup quot call +gt+ =
15 [ i 1 + i [ seq set-nth-unsafe ] bi-curry@ bi* 2drop i t ]
22 : bubble-sort-with! ( seq quot: ( obj1 obj2 -- <=> ) -- )
23 over length 2 < [ 2drop ] [ (bubble-sort-with!) ] if ; inline
25 : bubble-sort! ( seq -- ) [ <=> ] bubble-sort-with! ;