1 ! Copyright (C) 2014 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: kernel locals math math.order math.ranges sequences
11 :: (bubble-sort!) ( 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! ( seq quot: ( obj1 obj2 -- <=> ) -- )
23 over length 2 < [ 2drop ] [ (bubble-sort!) ] if ; inline
25 : natural-bubble-sort! ( seq -- )
26 [ <=> ] bubble-sort! ;