(單選,填字母) A.List1.Clear/B.List1.List=““/C.List1.Text=““/D.List1.Caption=“空白“)。 (2)實現(xiàn)分段排序功能的VB程序如下,請在橫線處填入合適的代碼。 (3)程序中代碼有錯,請改正。 Dim a(1 To 1000)As Integer Dim n As Integer Private Sub Command1_Click ( ) '輸入數(shù)據(jù)總量n,隨機(jī)生成n個數(shù)據(jù)保存在數(shù)組 'a(1)~a(n)中,并在List1中顯示數(shù)據(jù),代碼略 End Sub Private Sub Command2_Click ( ?。?br />Dim b(1 To 10000)As Integer Dim p1 As Integer,p2 As Integer,t1 As Integer,t2 As Integer Dim t As Integer,k As Integer,i As Integer,j As Integer p1=1 t1=leng(p1) p2=p1+t1 Do While p2<=n ①
i=p1:j=p2:t=1 Do While i<p2 Or j<p2+t2 If j>=p2+t2 Or i<p2 And a(i)<a(j) Then b(t)=a(i):i=i+1 Else b(t)=a(j):j=j+1 End If t=t+1 Loop For k=1 To ②
a(k)=b(k) Next k t1=t1+t2 p2=p1+p2 Loop '在List2中輸出數(shù)組a(i)的值,代碼略 End Sub Function Leng(ByVal p As Integer) As Integer '該函數(shù)返回數(shù)組a中數(shù)組下標(biāo)p開始的升序有序段的長度,代碼略 End Function
(填:是/否)。 (2)實現(xiàn)上述功能的VB程序如下,請在橫線處填入合適的代碼。 Const n=9'總?cè)藬?shù) Const m=6'已知的親戚關(guān)系數(shù) Dim a(1 To n) As String,b(1 To n) As String Dim f(1 To n) As String'記錄不同的親戚鉤碼串成員,每條親戚鉤碼串內(nèi)互為親戚 Dim k As Integer'親戚鉤碼串的數(shù)目 Private Sub Form_Load ( ?。?br />'初始化List1和List2,生成m條親戚關(guān)系,每條親戚關(guān)系的編號對應(yīng)存儲在數(shù)組a(i)和b(i)'中,在List1中輸出a(i)和b(i),代碼略 End Sub Private Sub Command1_Click ( ) Dim i As Integer,x As Integer,y As Integer f(1)=a(1)+b(1)'利用a(1)、b(1)生成第一條鉤碼串存儲在f(1)中 k=1'k為鉤碼串編號 For i=2 To m x=root(a(i),0):y=root(b(i),0)'x為調(diào)用函數(shù)獲取a(i)所在的鉤碼串編號 If x=0 And y=0 Then k=k+1:①
'根據(jù)x與y分類討論 If x<>0 And y=0 Then f(x)=f(x)+b(i) If x=0 And y<>0 Then f(y)=f(y)+a(i) If x<>y And x<>0 And y<>0 Then'x、y在不同鉤碼串則將兩條鉤碼串合并 f(x)=f(x)+f(y):f(y)=f(k):k=k-1 End If Next i For i=1 To n'輸出每個人所在鉤碼的頂端編號 x=root(CStr(i),0):y=root(CStr(i),1)'Cstr
函數(shù)用于去除字符前導(dǎo)空格 If x<>0 Then If y=Len(f(x)) ThenList2.AddItem Str(i)+““+CStr(i) If y<>Len(f(x)) Then List2.AddItem Str(i)+““+②
End If Next i End Sub '按鈕Command2的功能為判斷輸入的兩個人是否為親戚關(guān)系,代碼略 Function root(a As String,b As Integer) As Integer'參數(shù)a表示待查找目標(biāo),參數(shù)b '表示返回值類型,0表示返回目標(biāo)所在鉤碼串編號,1表示返回目標(biāo)在該鉤碼串中的位置 Dim m As Integer,n As Integer,i As Integer,j As Integer m=0:n=0:i=k:j=0 Do While i>0 If a=Mid(f(i),Len(f(i))-j,1)Thenm=i:n=Len(f(i))-j:Exit Do j=j+1 If j=Len(f(i)) Then i=i-1:j=0 Loop If ③