在vb中求冒泡法排序所用时间

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:58:39
最好要有代码

Option Base 0
Private Sub Command1_Click()
Dim a()
Dim start_time As Double
Dim finish_time As Double
a = Array(1, 4, 9, 2, 8, 5, 7, 6, 3, 11, 13, 16, 20, 18, 55, 21, 40, 63, 27, 28, 12, 14, 15, 19, 17, 22)
Print Join(a, ",")
start_time = Timer
paixu a()
finish_time = Timer
Print Join(a, ",")
If finish_time = start_time Then
Print "本次排序用时少于1ms"
Else
Print "本次排序用时:", finish_time - start_time
End If
End Sub
Private Sub paixu(ByRef b())

For i = 0 To UBound(b) - 1
For j = i To UBound(b)
If b(i) > b(j) Then
t = b(i)
b(i) = b(j)
b(j) = t
End If
Next j
Next i
End Sub

小范围更本看不出效果