03-04-2023, 06:14 PM
@TerryRitchie A working example for you:
Code: (Select All)
Screen _NewImage(800, 600, 32)
Type DATATYPE
a As Integer
b As Integer
c As Integer
End Type
Const Limit = 1000000 'one million defalt limit
ReDim SortedList(1 To Limit) As DATATYPE
For i = 1 To Limit
SortedList(i).a = Int(Rnd * 32767) + 1
SortedList(i).b = Int(Rnd * 32767) + 1
SortedList(i).c = Int(Rnd * 32767) + 1
Next
For i = 1 To 30
Print SortedList(i).a, SortedList(i).b, SortedList(i).c
Next
Sleep
FakeSort SortedList()
Print
Print "=== Sorted ==="
Print
For i = 1 To 30
Print SortedList(i).a, SortedList(i).b, SortedList(i).c
Next
Sub FakeSort (Array() As DATATYPE)
Dim S(1 To 32767) As String
Dim TempArray(1 To Limit) As DATATYPE
For i = 1 To Limit 'build the sorted index in a single pass
S(Array(i).a) = S(Array(i).a) + MKL$(i)
Next
Count = 0
For i = 1 To 32767
For J = 1 To Len(S(i)) Step 4 'we stored our index as long values
Count = Count + 1
t$ = Mid$(S(i), J, 4)
index = CVL(t$)
TempArray(Count) = Array(index)
Next
Next
For i = 1 To Limit
Array(i) = TempArray(i)
Next
End Sub