Const n = 8
Dim a(1 To n) As Integer, b(1 To n) As Integer
Private Sub Form_Load()
‘随机产生n个[1,20]之间的不重复的正整数,并在list1中显示,具体代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer, p as integer, p as integer
For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(j) < a(j - 1) Then
t = a(j):a(j) = a(j - 1): a(j - 1) = t
End If
Next j
Next i
p = n: ‘①
For i = 1 To n Step 2
‘②
b(i + 1) = a(q)
p = p - 2
q = q + 1
Next i
For i = 1 To n
List2.AddItem Str(b(i))
Next i
End Sub
① ②