Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
m (J code brought closer to the specification)
m (→‎{{header|J}}: fix lang tags)
Line 569: Line 569:


=={{header|J}}==
=={{header|J}}==
<lang J>
<lang j>
bubbleSort=: |. @: ((([ (>. , <.) {.@]) , }.@])/^:_)
bubbleSort=: |. @: ((([ (>. , <.) {.@]) , }.@])/^:_)
</lang>
</lang>
Line 575: Line 575:
Test program:
Test program:


<lang J>
<lang j> ?. 10 $ 10
?. 10 $ 10
4 6 8 6 5 8 6 6 6 9
4 6 8 6 5 8 6 6 6 9
bubbleSort ?. 10 $ 10
bubbleSort ?. 10 $ 10
Line 582: Line 581:
</lang>
</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.
For the most part, bubble sort works against J's strengths. However, once a single pass has been implemented as a list operation, <code>^:_</code> tells J to repeat this until the result stops changing.


=={{header|Java}}==
=={{header|Java}}==