Sorting algorithms/Selection sort: Difference between revisions

m
→‎{{header|Ruby}}: correct a couple of typos
(→‎{{header|Ruby}}: use idiomatic Ruby)
m (→‎{{header|Ruby}}: correct a couple of typos)
Line 2,684:
 
puts "sequential_sort([9, 6, 8, 7, 5]): #{sequential_sort([9, 6, 8, 7, 5])}"
# =>prints: sequential_sort([09, 16, 28, 37, 4,5]): [5, 6, 7, 8, 9]</lang>
 
 
 
# more efficient version - swaps the array's elements in place
 
def sequential_sort_with_swapping(array)
array.each_with_index do |element, index|
Line 2,705 ⟶ 2,709:
end
 
puts "sequential_sort_with_swapping([97, 6, 5,9,8, 74, 53,1,2,0]): #{sequential_sort_with_swapping([97, 6, 5,9,8, 74, 53,1,2,0])}"
# prints: sequential_sort_with_swapping([7,6,5,9,8,4,3,1,2,0]): [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
ary = [7,6,5,9,8,4,3,1,2,0]
p ary.selectionsort!
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</lang>
 
=={{header|Run BASIC}}==
Anonymous user