Const n = 10
Dim a(1 To n) As Integer
Private Sub Form_Load()
For i = 1 To n
a(i) = ‘产生两位随机正整数
List1.AddItem Str(a(i))
Next i
End Sub
Private Sub Command1_Click()
Dim p As Integer, q As Integer, pos1 As Integer, pos2 As Integer, t As Integer
p = 1: q = n
Do While
If a(p) <= a(p + 1) Then
pos1 = p: pos2 = p + 1
Else
pos1 = p + 1: pos2 = p
End If
For i = p To q
If a(i) < a(pos1) Then
pos2 = pos1
pos1 = i
ElseIf a(i) < a(pos2) Then
pos2 = i
End If
Next i
If pos1 <> p Then t = a(pos1): a(pos1) = a(p): a(p) = t
If pos2 = p Then
If pos2 <> q Then t = a(pos2): a(pos2) = a(q): a(q) = t
p = p + 1: q = q - 1
Loop
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub