Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(→{{header|Clojure}}: Clojure bubble sort, the most un-functional Clojure code I've written...) |
(J style solution) |
||
Line 569:
=={{header|J}}==
<lang J>
bubbleSort=: (([ (>. , <.) {.@]) , }.@])/^:_
)</lang>
Test program:
<lang J>
?. 10 $ 10
4 6 8 6 5 8 6 6 6 9
bubbleSort ?. 10 $ 10
9 8 8 6 6 6 6 6 5 4
</lang>
For the most part, bubble sort works against J's strengths. However, once a single pass has been implemented as a list operation, ^:_ tells J to repeat this until the result stops changing.
|