Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
Line 107: Line 107:
new_array = [3, 78, 4, 23, 6, 8, 6].sort {|a,b| a % 2 <=> b}
new_array = [3, 78, 4, 23, 6, 8, 6].sort {|a,b| a % 2 <=> b}
#=> [3, 78, 8, 4, 6, 23, 6]
#=> [3, 78, 8, 4, 6, 23, 6]
# Sort and modify the current object to be sorted
ary = [3, 78, 4, 23, 6, 8, 6]
ary.sort! {|a,b| a % 2 <=> b}
#ary => [3, 78, 8, 4, 6, 23, 6]
This sort is actually a C quicksort.
This sort is actually a C quicksort.