VB做冒泡排序,数度好慢,怎么样优化可以提高速度?谢谢
VB做冒泡排序,数度好慢,怎么样优化可以提高速度?谢谢Dim i, j As Integer
Dim t As Single
For i = 1 To 30000 - 1
For j = i + 1 To 30000
If paix(i) > paix(j) Then
t = paix(i)
paix(i) = paix(j)
paix(j) = t
End If
Next j
Next i
Private Sub Command2_Click() '选择法排序 Dim t As Long, i As Integer, j As Integer, t1 As Single, paixu(30000) As Single For i = 0 To 30000 paixu(i) = px(i) Next t = timeGetTime For i = 0 To 29999 k = i For j = i + 1 To 30000 If paixu(k) > paixu(j) Then k = j Next If k <> i Then t1 = paixu(i) '每次选择最小的数和当前顶层的数交换 paixu(i) = paixu(k) paixu(k) = t1 End If Next MsgBox timeGetTime - t End Sub Private Sub Command3_Click() '冒泡法排序 Dim t As Long, i As Integer, j As Integer, t1 As Single, paixu(30000) As Single For i = 0 To 30000 paixu(i) = px(i) Next t = timeGetTime For i = 0 To 29999 For j = 30000 To i + 1 Step -1 If paixu(j - 1) > paixu(j) Then t1 = paixu(j - 1) '每次相邻的两个数比较,逐步将最小的数交换到前面 paixu(j - 1) = paixu(j) paixu(j) = t1 End If Next Next MsgBox timeGetTime - t End Sub