Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(added algorithm description)
Line 121: Line 121:
std::cout << std::endl ;
std::cout << std::endl ;
}
}

==[[Forth]]==
[[Category:Forth]]
Sorts the 'cnt' cells stored at 'addr'. Uses forth local variables for clarity.

: bubble { addr cnt -- }
cnt 0 DO
addr cnt i - cells bounds DO
i 2@ > if i 2@ swap i 2! then
cell +LOOP
LOOP ;

This is the same algorithm done without the local variables:

: bubble ( addr cnt -- )
dup 0 DO
2dup i - cells bounds DO
i 2@ > if i 2@ swap i 2! then
cell +LOOP
LOOP ;


==[[Haskell]]==
==[[Haskell]]==