Jump to content

Sorting algorithms/Gnome sort: Difference between revisions

Line 2,760:
'adddeffffgghiiijjjjkkkkllnnooqsswww'
</pre>
=={{header|VBA}}==
{{trans|Phix}}<lang vb>Private Function gnomeSort(s As Variant) As Variant
Dim i As Integer: i = 1
Dim j As Integer: j = 2
Dim tmp As Integer
Do While i < UBound(s)
If s(i) <= s(i + 1) Then
i = j
j = j + 1
Else
tmp = s(i)
s(i) = s(i + 1)
s(i + 1) = tmp
i = i - 1
If i = 0 Then
i = j
j = j + 1
End If
End If
Loop
gnomeSort = s
End Function
Public Sub main()
Debug.Print Join(gnomeSort([{5, 3, 1, 7, 4, 1, 1, 20}]), ", ")
End Sub</lang>{{out}}
<pre>1, 1, 1, 3, 4, 5, 7, 20</pre>
=={{header|VBScript}}==
====Implementation====
255

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.