誰可以幫我把我的程序改寫成冒泡排序法。
Option Base 1
Private Sub Form_click()
Dim a%(), imin%, n%, i%, j%, t%, p%
Cls
Randomize
i = InputBox("输入数组的元素个数:")
ReDim a(i)
For j = 1 To i
a(j) = Int(Rnd * 200 + 1)
Next j
n = UBound(a)
For k = 1 To i
imin = a(k)
For j = 1 To i
If a(j) < a(k) Then
p = a(j)
a(j) = a(k)
a(k) = p
End If
Next j
Next k
For i = LBound(a) To UBound(a)
Print a(i);
If i Mod 8 = 0 Then Print
Next
End Sub
用泡排序法实现有N个元素数组的排序。N由键盘输入,数组元素的值在1~200之间,随机产生。
Private Sub Form_click()
Dim a%(), imin%, n%, i%, j%, t%, p%
Cls
Randomize
i = InputBox("输入数组的元素个数:")
ReDim a(i)
For j = 1 To i
a(j) = Int(Rnd * 200 + 1)
Next j
n = UBound(a)
For k = 1 To i
imin = a(k)
For j = 1 To i
If a(j) < a(k) Then
p = a(j)
a(j) = a(k)
a(k) = p
End If
Next j
Next k
For i = LBound(a) To UBound(a)
Print a(i);
If i Mod 8 = 0 Then Print
Next
End Sub