TheAlgorithms-Ruby/sorting/insertion_sort.rb
Vitor Oliveira e21120857d Clean up
2021-02-06 23:05:54 -08:00

17 lines
394 B
Ruby

def insertion_sort(array)
0.upto(array.length - 1).each do |index|
element = array[index]
position = index
while element < array[position - 1] && position > 0
array[position] = array[position - 1]
array[position - 1] = element
position -= 1
end
end
array
end
puts 'Enter a list of numbers separated by space'
list = gets
insertion_sort(list)
print list