Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
(→‎{{header|Scheme}}: Fix formatting, simplified, better variable names)
(→‎{{header|Scheme}}: The first function is not iterative. The two versions are actually equal.)
Line 2,329: Line 2,329:
(fix sort-step x)))</lang>
(fix sort-step x)))</lang>


This solution iteratively finds the fixed point of sort-step. A comparison function must be passed to bubblesort. Example usages:
This solution recursively finds the fixed point of sort-step. A comparison function must be passed to bubblesort. Example usages:
<lang scheme>(bubble-sort (list 1 3 5 9 8 6 4 2) >)
<lang scheme>(bubble-sort (list 1 3 5 9 8 6 4 2) >)
(bubble-sort (string->list "Monkey") char<?)</lang>
(bubble-sort (string->list "Monkey") char<?)</lang>


Here is a recursive bubble sort which sorts list 'l' using the comparator 'f':
Here is the same function, using a different syntax:


<lang scheme>(define (bsort l gt?)
<lang scheme>(define (bsort l gt?)