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

22 lines
365 B
Ruby

def bubble_sort(array)
n = array.length
loop do
swapped = false
(n - 1).times do |i|
if array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]
swapped = true
end
end
break unless swapped
end
array
end
puts 'Enter a list of numbers separated by space'
list = gets
bubble_sort(list)
print list