Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→{{header|AutoHotkey}}: Minor indentation and casing edit) |
No edit summary |
||
Line 620: | Line 620: | ||
allbutlast(x) = if not iseod(next x) then x else eod fi; |
allbutlast(x) = if not iseod(next x) then x else eod fi; |
||
end</lang> |
end</lang> |
||
=={{header|Mathematica}}== |
|||
A rule-based solution is only one line, for large lists this method is not optimal, not so because of the method but because of the usage of patterns in a rule based solution: |
|||
<lang Mathematica> |
|||
BubbleSort[input_]:=input//.{a___,i_,j_,b___}/;Not[OrderedQ[{i,j}]]:>{a,j,i,b} |
|||
</lang> |
|||
Example: |
|||
<lang Mathematica> |
|||
BubbleSort[{10, 3, 7, 1, 4, 3, 8, 13, 9}] |
|||
</lang> |
|||
gives back: |
|||
<lang Mathematica> |
|||
{1, 3, 3, 4, 7, 8, 9, 10, 13} |
|||
</lang> |
|||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== |