mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-11-16 19:50:00 +01:00
22 lines
No EOL
377 B
Ruby
22 lines
No EOL
377 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 if not swapped
|
|
end
|
|
|
|
array
|
|
end
|
|
puts "Enter a list of numbers seprated by space"
|
|
|
|
list = gets
|
|
bubble_sort(list)
|
|
print list |