为此,小李编写了一个VB程序,功能如下:运行程序,窗体加载时随机产生6个[0,9]的随机整数,并在列表框List1中依次显示排序前数据,单击“排序”按钮Command1,在列表框List2 中显示经过上述排序算法后的数据。运行结果如图所示。
实现上述功能的VB代码如下,但横线处代码有错,请改正。
Dim a(10) As Integer'数组a表示桶的编号,如a(0)表示第0号桶
Private Sub Command1_Click()
Dim i As Integer, j As Integer
For i = 0 To 10
For j = 1 To i 错①处
List2.AddItem CStr(i)
Next j
Next i
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 0 To 10'将数组初始化为0
a(i) = 0
Next i
For i = 1 To 6'产生6个[0,9]的随机数
t = Int(Rnd * 10)
a(t) = t + 1 '第t桶中小旗子数量加1 错②处
List1.AddItem CStr(t)
Next i
End Sub
① ②