Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (15 sloc) 336 Bytes
def bubble_sort(collection)
n = collection.length
begin
swapped = false
(n - 1).times do |i|
if collection[i] > collection[i + 1]
tmp = collection[i]
collection[i] = collection[i + 1]
collection[i + 1] = tmp
swapped = true
end
end
end until not swapped
collection
end
You can’t perform that action at this time.