Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
No edit summary
Line 1,896: Line 1,896:
_bsort _ = Nothing</lang>
_bsort _ = Nothing</lang>


This version is based on the above, but avoids sorting whole list each time. To implement this without a counter and retain using pattern matching, inner sorting is reversed, and then result is reversed back. Sorting is based on a predicate, e. g. (<) or (>).
This version is based on the above, but avoids sorting the whole list each time. To implement this without a counter and retain using pattern matching, inner sorting is reversed, and then the result is reversed back. Sorting is based on a predicate, e.g., (<) or (>).


<lang haskell>import Data.Maybe (fromMaybe)
<lang haskell>import Data.Maybe (fromMaybe)