Radix Sort

Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.



									Public Shared Sub RadixSort(ByRef data As Integer())
	Dim i As Integer, j As Integer
	Dim temp As Integer() = New Integer(data.Length - 1) {}

	For shift As Integer = 31 To -1 + 1 Step -1
		j = 0

		For i = 0 To data.Length - 1
			Dim move As Boolean = (data(i) << shift) >= 0

			If If(shift = 0, Not move, move) Then
				data(i - j) = data(i)
			Else
				temp(j) = data(i)
				j += 1
			End If
		Next

		Array.Copy(temp, 0, data, data.Length - j, j)
	Next
End Sub
								


Example

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


Output

									-58964
-119
-1
0
25
8547
78596