1. 程式人生 > >比較數的大小(冒泡法)

比較數的大小(冒泡法)

Private Sub Command1_Click()
Dim a(10) As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To 10
a(i) = 10 + Int(Rnd() * 1000)
Print a(i);
Next i
Print

For i = 1 To 9
For j = 1 To 10 - i
If a(j) < a(j + 1) Then
  swap a(j), a(j + 1)
End If
Next j
Next i

For i = 1 To 10
Print a(i);
Next i
Print
End Sub

Private Sub swap(a As Integer, b As Integer)
Dim t As Integer

t = a
a = b
b = t


End Sub