为此,编写了一个 VB 程序,功能如下:运行程序,窗体加载时随机产生 10 个随机整数,并在列表框 List1 中依次显示排序前数据,单击“排序”按钮 Command1,在列表框 List2 中
显示经过上述排序算法后的数据,运行结果如图 b 所示。实现上述功能的 VB 代码如下,但加框处代码有错,请改正。
Const n = 10
Dim a(1 To n) As Integer '生成 n 个随机数,存储在 a 数组,代码略
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer
For i = 2 To n
t = a(i) : j = i - 1
Do While t < a(j)
a(j + 1) = a(j) j = j – 1
If Then Exit Do ①
Loop
②
Next i
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
① ②