字典插入排序比快排还慢吗
以下是足彩14场扩展一场的笨方法,第一种是先扩再排序去重复,主要消耗在排序上。换成第二种字典法,添加字典序也慢如牛,主要消耗在Exists上。八十万数据要几分钟,而其他软件只需几秒,不知各位达人有什么好的快速算法。Public Function KZCS1(ByRef Arr() As String, ByRef Drr() As Double) As Double()
Dim I As Long
Dim J As Long
Dim Brr() As Double
Dim S As String
Dim HM As String
'Dim HMa As Double
Dim sQ As String
Dim sW As String
Dim N As Long
Dim uM As Long
N = 0
uM = UBound(Drr)
Dim Dic As New Dictionary
ReDim Brr((uM + 1) * (28 + 1)) As Double
Dim Dt As Date
Dt = Now
For I = 0 To uM
HM = Format(Drr(I), "00000000000000")
'Brr(N) = Drr(I):N = N + 1
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
For J = 1 To 14
S = Mid(HM, J, 1)
If J = 1 Then
sQ = ""
Else
sQ = Mid(HM, 1, J - 1)
End If
If J = 14 Then
sW = ""
Else
sW = Mid(HM, J + 1)
End If
If S = "3" Then
HM = sQ & "1" & sW
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
'Brr(N) = CDbl(HM): N = N + 1
HM = sQ & "0" & sW
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
'Brr(N) = CDbl(HM): N = N + 1
ElseIf S = "1" Then
HM = sQ & "3" & sW
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
'Brr(N) = CDbl(HM): N = N + 1
HM = sQ & "0" & sW
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
'Brr(N) = CDbl(HM): N = N + 1
ElseIf S = "0" Then
HM = sQ & "1" & sW
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
'Brr(N) = CDbl(HM): N = N + 1
HM = sQ & "3" & sW
If Not Dic.Exists(HM) Then
Dic.Add HM, 1
End If
'Brr(N) = CDbl(HM): N = N + 1
End If
Next J
DoEvents
Next I
MsgBox DateDiff("s", Dt, Now)
'Dt = Now
'QuickSort Brr, True, 0, UBound(Brr) '快排
'MsgBox DateDiff("s", Dt, Now)
'CQF brr '去重复
End Function
补充:VB , VBA