Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -0,0 +1,93 @@
|
|||
Sub countSort(rs() As Long, expo As Long)
|
||||
Dim As Long lb = Lbound(rs), ub = Ubound(rs)
|
||||
Dim As Long i, t
|
||||
Dim As Long salida(lb To ub), conteo(0 To 9)
|
||||
|
||||
For i = lb To ub
|
||||
t = (rs(i) \ expo) Mod 10
|
||||
conteo(t) += 1
|
||||
Next
|
||||
|
||||
For i = 1 To 9
|
||||
conteo(i) += conteo(i-1)
|
||||
Next
|
||||
|
||||
For i = ub To lb Step -1
|
||||
t = (rs(i) \ expo) Mod 10
|
||||
salida(lb + conteo(t) - 1) = rs(i)
|
||||
conteo(t) -= 1
|
||||
Next
|
||||
|
||||
For i = lb To ub
|
||||
rs(i) = salida(i)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Sub radixSort(rs() As Long)
|
||||
Dim As Long lb = Lbound(rs), ub = Ubound(rs)
|
||||
|
||||
' Find minimum value
|
||||
Dim As Long i, minVal = rs(lb)
|
||||
For i = lb + 1 To ub
|
||||
If rs(i) < minVal Then minVal = rs(i)
|
||||
Next
|
||||
|
||||
' If negative numbers exist, shift array to positive
|
||||
If minVal < 0 Then
|
||||
For i = lb To ub
|
||||
rs(i) -= minVal
|
||||
Next
|
||||
End If
|
||||
|
||||
' Find maximum value
|
||||
Dim As Long maxVal = rs(lb)
|
||||
For i = lb + 1 To ub
|
||||
If rs(i) > maxVal Then maxVal = rs(i)
|
||||
Next
|
||||
|
||||
' Do counting sort for every digit
|
||||
Dim As Long expo = 1
|
||||
While (maxVal \ expo) > 0
|
||||
countSort(rs(), expo)
|
||||
expo *= 10
|
||||
Wend
|
||||
|
||||
' If we shifted for negatives, shift back
|
||||
If minVal < 0 Then
|
||||
For i = lb To ub
|
||||
rs(i) += minVal
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub printArray(rs() As Long)
|
||||
Dim As Long lb = Lbound(rs), ub = Ubound(rs)
|
||||
Print "[ ";
|
||||
For i As Long = lb To ub
|
||||
Print rs(i);
|
||||
If i < ub Then Print ", ";
|
||||
Next
|
||||
Print " ]"
|
||||
End Sub
|
||||
|
||||
'--- Main Program ---
|
||||
Dim As Long i, array(-7 To 7)
|
||||
Dim As Long a = Lbound(array), b = Ubound(array)
|
||||
|
||||
Randomize Timer
|
||||
For i = a To b : array(i) = i : Next i
|
||||
|
||||
For i = a To b ' little shuffle
|
||||
Swap array(i), array(Int(Rnd * (b - a + 1)) + a)
|
||||
Next i
|
||||
|
||||
Print "unsort ";
|
||||
For i = a To b : Print Using "####"; array(i); : Next i
|
||||
|
||||
radixSort(array()) ' sort the array
|
||||
|
||||
Print !"\n sort ";
|
||||
For i = a To b : Print Using "####"; array(i); : Next i
|
||||
Print
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue