實現(xiàn)上述功能的VB程序如下,加框處代碼有錯,請改正。 Const n=10'變量n存儲待排序數(shù)據(jù)個數(shù) Dim d(1To n) As Integer'數(shù)組d存儲待排序數(shù)據(jù) Private Sub APrint ( ?。?br />'本過程實現(xiàn)在列表框一行中輸出數(shù)組d各個元素的值,代碼略。 End Sub Private Sub Command1_Click ( ?。?br />Dim i As Integer,j As Integer,tmp As Integer Dim m As Integer,low As Integer,high As Integer '先將待排序數(shù)據(jù)存儲在數(shù)組d中,代碼略。 List1.AddItem“-----------待排序數(shù)據(jù)------------“ Call Aprint'在列表框List1中輸出數(shù)組d的各個元素的值 List1.AddItem“-----------數(shù)據(jù)排序過程------------“ For i=2To n tmp=d(i) low=1 ′(1) Do While low<=high m=(low+high)\2 If tmp<=d(m) Then high=m-1 Else low=m+1 End If Loop For j=i-1To low Step-1 d(j+1)=d(j) Next j ′(2) Call APrint Next i End Sub
。 (2)請在橫線處填入合適的代碼。 Function check(s As String) As Integer Dim i As Integer,g1As Integer,g2As Integer,g3As Integer Dim c(1To 7)As Integer For i=1To 7 c(i)=Val(Mid(s,i,1)) Next i g1=c(1)Xor c(3)Xor c(5)Xor c(7) g2=c(2)Xor c(3)Xor c(6)Xor c(7) g3=c(4)Xor c(5)Xor c(6)Xor c(7) If g1+g2+g3=0Then check=0Else check=
End Function Private Sub Command1_Click ( ) Dim i As Integer,m As Integer,Outs As String m=
If m=0Then Text2.Text=“驗證正確,數(shù)據(jù)無錯誤“ Else For i=1To 7 If i=m Then Outs=Outs+Chr(Asc(Mid(Text1.Text,i,1)) Xor
) Else Outs=Outs+Mid(Text1.Text,i,1) End If Next i Text2.Text=“第“+Str(m)+“位上數(shù)據(jù)有錯誤,正確編碼應為:“+Outs End If End Sub