依據(jù)對分查找思想,設計一個在數(shù)組a中查找數(shù)據(jù)key的程序。實現(xiàn)該功能的VB程序如下,但加框處代碼有錯,請改正。 Private Sub Command1_Click ( ) Const n=6 Dim a(1 To n)As Integer,flag As Boolean Dim i As Integer,j As Integer,m As Integer,key As Integer '讀取一組正整數(shù),按上述規(guī)則存入數(shù)組a中,代碼略。 key=Val(Text1.Text) i=1 j=(n+1)\2 flag=False Do While And Not flag'(1) m=(i+j)\2 If key=a(m) Then flag=True Elself key<a(m) Then j=m-1 Else i=m+1 End If Loop If Not flag And j>0 Then m='(2) If key=a(m) Then flag=True End If If flag Then Text2.Text=Str(m) Else Text2.Text=“找不到“ End If End Sub