题型:填空题 题类:常考题 难易度:困难
浙江省台州市联谊五校2018-2019学年高二下学期信息技术期中考试试卷
实现该功能的VB程序如下,但加框处代码有错,请改正。
Const n = 10
Dim a(1 To n) As Integer
Private Sub Form_Load()
随机产生 n 个不重复的整数存数组 a,并在列表框 list1 中显示。代码略。
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer
Dim imin1 As Integer, imin2 As Integer
For i = 1 To n \ 2
imin1 = i: imin2 = i + 1
If a(imin1) > a(imin2) Then t = imin1: imin1 = imin2: imin2 = t
For j = i + 2 To n - i + 1
If a(j) < a(imin1) Then
imin2 = imin1: imin1 = j
'①
imin2 = j
End If
Next j
If i <> imin1 Then t = a(i): a(i) = a(imin1): a(imin1) = t
If imin2 = i Then '②
If n - i + 1 <> imin2 Then
t = a(n - i + 1): a(n - i + 1) = a(imin2): a(imin2) = t
End if
Next i
For i = 1 To n
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
① ②
原始数据 | 65 | 57 | 59 | 44 | 45 | 69 |
第1遍 | 44 | 65 | 57 | 59 | 45 | 69 |
第2遍 | 44 | 45 | 55 | 57 | 59 | 69 |
第3遍 | 44 | 45 | 57 | 65 | 59 | 69 |
… | … | … | … | … | … | … |
试题篮