第1个回答 2019-12-26
首先要求被查找的表是已经排序好的,我机器上没VB,凭记忆写,格式可能稍有错误。
顺序查找:
Private
Function
ShunXu(
Array()
as
integer,
data
as
integer
)
as
integer
dim
i
as
integer
for
i
=
0
to
(len(Array)
-
1)
if
Array(i)
=
data
then
ShunXu
=
i
end
if
next
i
End
Function
折半查找:
private
function
ZheBan(
Array()
as
integer,
data
as
integer
)
as
integer
dim
i
as
integer
dim
intHigh
as
integer
dim
intLow
as
integer
dim
intMid
as
integer
while
(intLow
<=
intHigh)
intMid
=
(intLow
+
intHigh)
/
2
if
Array(intMid)
>
data
then
intHigh
=
intMid
-
1
elseif
Array(intMid)
<
data
then
intLow
=
intMid
+
1
else
ZheBan
=
intMid
end
if
wend
end
function本回答被提问者采纳