Sorting algorithms/Comb sort: Difference between revisions

no edit summary
(→‎{{header|REXX}}: updated the sort code to reflect the updated comb sort algorithm.)
No edit summary
Line 892:
sorted -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7</pre>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=ade780ac2893fcfc95bf0d3feff6a3a8 Click this link to run this code]'''
<lang gambas>Public Sub Main()
Dim siToSort As Short[] = [249, 28, 111, 36, 171, 98, 29, 448, 44, 147, 154, 46, 102, 183, 24,
120, 19, 123, 2, 17, 226, 11, 211, 25, 191, 205, 77]
Dim siStart As Short
Dim siGap As Short = siToSort.Max
Dim bSorting, bGap1 As Boolean
Print "To sort: -"
ShowWorking(siToSort)
Print
Repeat
bSorting = False
siStart = 0
If siGap = 1 Then bGap1 = True
 
Repeat
If siToSort[siStart] > siToSort[siStart + siGap] Then
Swap siToSort[siStart], siToSort[siStart + siGap]
bSorting = True
End If
Inc siStart
Until siStart + siGap > siToSort.Max
 
If bSorting Then ShowWorking(siToSort)
siGap /= 1.3
If siGap < 1 Then siGap = 1
Until bSorting = False And bGap1 = True
End
'-----------------------------------------
Public Sub ShowWorking(siToSort As Short[])
Dim siCount As Short
 
For siCount = 0 To siToSort.Max
Print Str(siToSort[siCount]);
If siCount <> siToSort.Max Then Print ",";
Next
 
Print
 
End</lang>
Output:
<pre>
To sort: -
249,28,111,36,171,98,29,448,44,147,154,46,102,183,24,120,19,123,2,17,226,11,211,25,191,205,77
 
77,28,111,36,171,98,29,448,44,147,154,46,102,183,24,120,19,123,2,17,226,11,211,25,191,205,249
77,11,111,25,171,98,29,448,44,147,154,46,102,183,24,120,19,123,2,17,226,28,211,36,191,205,249
77,11,111,2,17,98,28,211,36,147,154,46,102,183,24,120,19,123,25,171,226,29,448,44,191,205,249
46,11,111,2,17,19,28,25,36,147,29,77,44,183,24,120,98,123,211,171,226,154,448,102,191,205,249
36,11,29,2,17,19,24,25,46,123,111,77,44,154,28,102,98,147,211,171,226,183,448,120,191,205,249
24,11,29,2,17,19,36,25,28,102,98,77,44,154,46,123,111,120,191,171,226,183,448,147,211,205,249
17,11,29,2,24,19,36,25,28,102,46,77,44,120,98,123,111,154,191,147,211,183,249,171,226,205,448
2,11,19,17,24,28,36,25,29,44,46,77,102,111,98,123,120,154,183,147,171,191,205,211,226,249,448
2,11,19,17,24,25,29,28,36,44,46,77,98,111,102,123,120,147,171,154,183,191,205,211,226,249,448
2,11,17,19,24,25,28,29,36,44,46,77,98,102,111,120,123,147,154,171,183,191,205,211,226,249,448
</pre>
=={{header|Go}}==
<lang go>package main
Anonymous user