Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Selection sort in ruby
def selection_sort array
(array.length-1).times do |i|
minindex = i
minvalue = array[i]
(i).upto(array.length-1) do |j|
if array[j] < minvalue
minindex = j
minvalue = array[j]
end
if minvalue < array[i]
array[i] , array[minindex] = minvalue, array[i]
end
end
end
array
end
array = [10,5,8,93,6,2]
print selection_sort(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment