2.
有一组正整数,要求仅对其中的奇数进行升序排序。排序后在列表框List2中也仅显示奇数部分数据,结果如图所示。
实现上述功能的VB代码如下,但加框处有错,请改正。
Const n=10
Dim a (1 To n) As Integer
Private Sub Command1_Click()
Dim t As Integer, i As Integer, j As Integer, m As Integer
Dim tmp As Integer
'读取一组正整数,存储在数组a中,并显示在列表框List1,代码略
i=1
Do While i<=n
For j=n To i+1 Step-1
If a(j) Mod 2=1 Then
If ① Then
tmp =a(j):a(j)=a(j-1):a(j-1)=tmp
t=t+1
End If
End If
Next j
If ② Then m=m+1
i=i+1
Loop
For i=1 to m
List2.AddItem Str(a(i))
Next i
List2.AddItem "一共交换了"& t & "次"
End Sub
① ②