VB解析冒泡排序为什么内循环要8-i
输入8个数字,从小到大,用冒泡排序
Dim a(10) As Integer
Private Sub Command1_Click()
For i = 1 To 8
x = Int(90 * Rnd) + 10
a(i) = x
Text1 = Text1 & x & " "
Next i
End Sub
Private Sub Command2_Click()
For i = 1 To 7 '外循环,冒泡排序这一句有什么用
For j = 1 To 8 - i '内循环,冒泡排序这一句有什么用 为什么要8-i,
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
For i = 1 To 8
Text2 = Text2 & a(i) & " "
Next i
End Sub
Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub
RISEBY
ITMISS