Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
Line 208: | Line 208: | ||
loop ; |
loop ; |
||
Version with ''O(n)'' best case: |
|||
⚫ | |||
: 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 ; |
|||
⚫ | |||
create test |
create test |
||
8 , 1 , 4 , 2 , 10 , 3 , 7 , 9 , 6 , 5 , |
8 , 1 , 4 , 2 , 10 , 3 , 7 , 9 , 6 , 5 , |