TheAlgorithms-Ruby/sorting/comb_sort.rb
Vitor Oliveira 8bb781f790 Minor fixes
2021-09-03 13:24:58 -07:00

22 lines
466 B
Ruby

def comb_sort(array)
gap = array.length
swaps = true
while (gap > 1) || swaps
gap = [1, (gap / 1.25).to_i].max
swaps = false
0.upto(array.length - gap - 1) do |i|
if array[i] > array[i + gap]
array[i], array[i + gap] = array[i + gap], array[i]
swaps = true
end
end
end
array
end
if $0 == __FILE__
puts 'Enter a list of numbers separated by space'
list = gets.split.map(&:to_i)
p insertion_sort(list)
end