mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-11-16 19:50:00 +01:00
22 lines
466 B
Ruby
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
|