(單選,填字 母:A.Form.Caption=“生成合唱隊列”/B.Label1.Caption=“生成合唱隊列”/C.Form1.Caption=“生成合唱隊列”) (2)實現(xiàn)上述功能的VB程序如下,請在橫線處①②③填入合適代碼。 (3)程序加框處代碼有錯,請改正。 Dim a(1 To 100)As Integer Dim n As Integer Private Sub Command1_Click ( ) '在文本框 Text1 中輸入 n(n<=100) '排序前數(shù)據(jù)存儲在數(shù)組 a 中,并在文本框 List1 中顯示 '代碼略 End Sub Private Sub Command2_Click ( ) Dim i As Integer,j As Integer,t As Integer Dim pMax1 As Integer,pMax2 As Integer pMax1=n\2+1:pMax2=n\2 If①Then For i=1 To n If a(i)>a(pMax1)Then t x k w=a(pMax1):a(pMax1)=a(i):a(i)=t Next i pMax1=pMax1+1 End If For i=1 To n\2 If ②Then t=a(pMax1):a(pMax1)=a(pMax2):a(pMax2)=t j=pMax1 Mod n+1 Do While j<>pMax2 If a(j)>a(pMax1)Then t=a(pMax1):a(pMax1)=a(j):a(j)=t t=a(pMax2):a(pMax2)=a(j):a(j)=t t=a(pMax2):a(pMax2)=a(j):a(j)=t End If ③ Loop pMax1=pMax1+1 pMax2=pMax2-1 Next i For i=1 To n List2.AddItem Str(a(i)) Next i End Sub
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數(shù)量超過閾值 p 時,由系統(tǒng)向用戶 A 推薦用戶 B。 編寫 VB 程序,實現(xiàn)好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據(jù)如圖所示數(shù)據(jù),若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: