Sorting algorithms/Comb sort: Difference between revisions
Content added Content deleted
Line 2,552: | Line 2,552: | ||
RETURN</lang> |
RETURN</lang> |
||
=={{header|VBA}}== |
|||
{[trans|Phix}}<lang vb>Function comb_sort(ByVal s As Variant) As Variant |
|||
Dim gap As Integer: gap = UBound(s) |
|||
Dim swapped As Integer |
|||
Do While True |
|||
gap = WorksheetFunction.Max(WorksheetFunction.Floor_Precise(gap / 1.3), 1) |
|||
swapped = False |
|||
For i = 0 To UBound(s) - gap |
|||
si = Val(s(i)) |
|||
If si > Val(s(i + gap)) Then |
|||
s(i) = s(i + gap) |
|||
s(i + gap) = CStr(si) |
|||
swapped = True |
|||
End If |
|||
Next i |
|||
If gap = 1 And Not swapped Then Exit Do |
|||
Loop |
|||
comb_sort = s |
|||
End Function |
|||
Public Sub main() |
|||
Dim s(9) As Variant |
|||
For i = 0 To 9 |
|||
s(i) = CStr(Int(1000 * Rnd)) |
|||
Next i |
|||
Debug.Print Join(s, ", ") |
|||
Debug.Print Join(comb_sort(s), ", ") |
|||
End Sub</lang>{{out}} |
|||
<pre>45, 414, 862, 790, 373, 961, 871, 56, 949, 364 |
|||
45, 56, 364, 373, 414, 790, 862, 871, 949, 961</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|D}} |
{{trans|D}} |