Added Bubble Sort

This commit is contained in:
Chetan Kaushik 2016-07-25 23:03:27 +05:30 committed by GitHub
parent cf04302347
commit 04d7fc3696

22
BubbleSort.rb Normal file
View file

@ -0,0 +1,22 @@
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