Sorting algorithms/Comb sort: Difference between revisions

(→‎{{header|Ruby}}: addd python)
Line 192:
{CombSort Arr}
{Show {Array.toRecord unit Arr}}</lang>
 
=={{header|Python}}==
<lang python>def combsort(input):
gap = len(input)
swaps = True
while gap > 1 or swaps:
gap = int(gap / 1.25)
swaps = False
for i in range(len(input) - gap):
if input[i] > input[i+gap]:
input[i], input[i+gap] = input[i+gap], input[i]
swaps = True
 
x = [23, 76, 99, 58, 97, 57, 35, 89, 51, 38, 95, 92, 24, 46, 31, 24, 14, 12, 57, 78]
combsort(x)
print x</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|Ruby}}==
Anonymous user