Jump to content

Sorting algorithms/Comb sort: Difference between revisions

add Ruby
(added ocaml)
(add Ruby)
Line 98:
done
;;</lang>
 
=={{header|Ruby}}==
<lang ruby>class Array
def combsort!
gap = size
swaps = true
until gap <= 1 and swaps
gap = (gap / 1.25).to_int
swaps = false
0.upto(size - gap - 1) do |i|
if self[i] > self[i+gap]
self[i], self[i+gap] = self[i+gap], self[i]
swaps = true
end
end
end
self
end
end
 
p [23, 76, 99, 58, 97, 57, 35, 89, 51, 38, 95, 92, 24, 46, 31, 24, 14, 12, 57, 78].combsort!</lang>
results in
<pre>[12, 14, 23, 24, 24, 31, 35, 38, 46, 51, 57, 57, 58, 76, 78, 89, 92, 95, 97, 99]</pre>
 
 
=={{header|TI-83 BASIC}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.