Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(More pythonic) |
No edit summary |
||
Line 237: | Line 237: | ||
return this; |
return this; |
||
} |
} |
||
==[[MAXScript]]== |
|||
[[Category:MAXScript]] |
|||
fn bubbleSort arr = |
|||
( |
|||
while true do |
|||
( |
|||
changed = false |
|||
for i in 1 to (arr.count - 1) do |
|||
( |
|||
if arr[i] > arr[i+1] then |
|||
( |
|||
swap arr[i] arr[i+1] |
|||
changed = true |
|||
) |
|||
) |
|||
if not changed then exit |
|||
) |
|||
arr |
|||
) |
|||
-- Usage |
|||
myArr = #(9, 8, 7, 6, 5, 4, 3, 2, 1) |
|||
myArr = bubble myArr |
|||
==[[Perl]]== |
==[[Perl]]== |