Comb Sort

Comb sort is sorting algorithm and it is a variant of Bubble sort, the Comb Sort increases the gap used in comparisons and exchanges.



									Public Shared Sub CombSort(ByRef data As Integer())
	Dim gap As Double = data.Length
	Dim swaps As Boolean = True

	While gap > 1 OrElse swaps
		gap /= 1.24733095010398

		If gap < 1 Then
			gap = 1
		End If

		Dim i As Integer = 0
		swaps = False

		While i + gap < data.Length
			Dim igap As Integer = i + CInt(Math.Truncate(gap))

			If data(i) > data(igap) Then
				Dim temp As Integer = data(i)
				data(i) = data(igap)
				data(igap) = temp
				swaps = True
			End If

			i += 1
		End While
	End While
End Sub
								


Example

									Dim data() As Integer = { -1, 25, -58964, 8547, -119, 0, 78596 }
CombSort(data)
								


Output

									-58964
-119
-1
0
25
8547
78596