排序 ,对分法查找 。
--------------
只是单字,还有一种方法
多用点内容,把所有的字根据内码换算成下标,
如,先转正数,然后 减于 啊 的数值,换算成0-N
读取时,每读到一个,按上面换算,换算结果当作下标,保存编码
使用时,按上面换算,当作下标 ,直接读编码
---------------
嗯,不用查表了。
Const adOpenStatic = 3 Const adLockOptimistic = 3 Const adCmdText = &H0001 Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") strPathToTextFile = "C:\Scripts\" strFile = "Test.txt" objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & strPathtoTextFile & ";" & _ "Extended Properties=""text;HDR=NO;FMT=Delimited""" objRecordSet.Open "Select DISTINCT * FROM " & strFile, _ objConnection, adOpenStatic, adLockOptimistic, adCmdText ……………………………… ……………………
有序数的快速查找方法(非递归法) Private Sub Command1_Click() Dim dd(27) As Long Dim aa As Long Dim v As Long dd(0) = 75 dd(1) = 80 dd(2) = 85 dd(3) = 90 dd(4) = 95 dd(5) = 100 dd(6) = 106 dd(7) = 112 dd(8) = 118 dd(9) = 125 dd(10) = 132 dd(11) = 140 dd(12) = 150 dd(13) = 160 dd(14) = 180 dd(15) = 200 dd(16) = 224 dd(17) = 250 dd(18) = 280 dd(19) = 315 dd(20) = 355 dd(21) = 400 dd(22) = 450 dd(23) = 500 dd(24) = 560 dd(25) = 630 dd(26) = 710 dd(27) = 800 aa = 280 '要查找的数字 v = NumFind(dd, aa) '调用查找函数 If v = -1 Then MsgBox "没发现要查找的数据", vbExclamation, "提示" Else MsgBox "当前要查找的:" & aa & " 值在dd数组的第:" & v & " 个元素。", vbInformation, "信息" End If End Sub Public Function NumFind(ByRef Myarray, FNumber As Variant) As Long Dim K As Long, I As Long Dim L1 As Long, R1 As Long Dim l As Long, R As Long l = LBound(Myarray): R = UBound(Myarray) NextLoop: K = (l + R) Mod 2 If K = 1 Then '中点 I = (l + R + 1) \ 2 Else I = (l + R) \ 2 End If If Myarray(I) <> FNumber Then If Myarray(I) > FNumber Then L1 = l: R1 = I Else L1 = I: R1 = R End If If (R1 - L1) = 1 Then '第一个和最后一个 If Myarray(L1) = FNumber Then NumFind = L1 ElseIf Myarray(R1) = FNumber Then NumFind = R1 Else NumFind = -1 '没有发现 End If Else l = L1: R = R1 GoTo NextLoop End If Else NumFind = I End If End Function