\ Bubble Sort
\ Taken from http://rosettacode.org 
\ 4tH version 2011, Hans Bezemer

[UNDEFINED] sort     [IF]
[UNDEFINED] precedes [IF]
defer precedes                         ( addr addr -- flag )
[THEN]                                 \ compatible with QSORT

: sort                                 ( addr len -- )
  dup 1 > if                           \ protect from single element arrays
    begin
      1- 2dup true -rot cells bounds   ( sorted addr len-1 )
      ?do
        i @ i 1+ @ over over precedes  ( mark unsorted )
        if drop drop else i ! i 1+ ! dup xor then
[UNDEFINED] 4TH# [IF]
      1 cells +loop                    \ sorted
[ELSE]
      loop                             \ sorted
[THEN]
    until
  then 2drop
;
[THEN]
