小明使用VB实现该排序,设计功能如下:随机生成两位正整数并显示在List1中,单击按钮“Command1”后将排序完成的数据显示在List2中。界面如图所示。
请回答以下问题:
Const n= 5 '矩阵大小
Dim a(1To n*n) As Integer
Private Sub Form_Load()
'随机生成n*n的矩阵数据,并依次保存在数组a(1)~a(n*n)中
'以n*n矩阵形式在list 1中显示数据,代码略
End Sub
Private Sub Command 1_Click()
Dim i As Integer, j As Integer, k As Integer, t As Integer
Dim startpos As Integer, endpos As Integer, s As String
For i= 2 To 2*n-2
If i<=n Then
startpos=(i-1) *n+ 1
endpos=i
Else
startpos= ①
endpos=(i-n+1) *n
End If
Do While startpos>endpos
②
j=startpos-n+1
Do While j>=endpos
If a(j) <a(k) Then k=j
j=j-n+1
Loop
If k<>startpos Then
t=a(k) :a(k) =a(startpos) :a(startpos) =t
End If
start pos=startpos-n+ 1
Loop
Next i
For i=1To n
s=””
For j=1To n
s=s+ ③
Next j
List 2.Add Item s
Next i
End Sub
① ② ③