Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→[[Perl]]
No edit summary |
|||
Line 71:
N.B. Of course, there's no need to implement bubble sort in perl as it has sort built-in.
==[[Ruby]]==
new_array = [3, 78, 4, 23, 6, 8, 6].sort
#=> [3, 4, 6, 6, 8, 23, 78]
# Sort on arbitrary criteria:
new_array = [3, 78, 4, 23, 6, 8, 6].sort {|a,b| a % 2 <=> b}
#=> [3, 78, 8, 4, 6, 23, 6]
# Sort in place:
a = [3, 78, 4, 23, 6, 8, 6]
a.sort!
a
#=> [3, 4, 6, 6, 8, 23, 78]
|