Sorting algorithms/Bubble sort: Difference between revisions

Line 208:
loop ;
 
Version with ''O(n)'' best case:
Test either version with this:
: bubble ( addr len -- )
begin
1- 2dup true -rot ( sorted addr len-1 )
cells bounds ?do
i 2@ bubble-test if
i 2@ swap i 2!
drop false ( mark unsorted )
then
cell +loop ( sorted )
until 2drop ;
 
Test eitherany version with this:
create test
8 , 1 , 4 , 2 , 10 , 3 , 7 , 9 , 6 , 5 ,
Anonymous user