如何实现冒泡排序算法
发布网友
发布时间:2022-05-22 00:20
我来回答
共1个回答
热心网友
时间:2022-05-22 02:12
For i = 1 To 10
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
Dim i As Integer
Dim j As Integer
Dim temp As Integer
Private Sub Command1_Click()
Dim s As String
s = ""
Print "原数组为:"
For i = 1 To 10
s = s & a(i) & " "
Next i
Print s
Print
For i = 1 To 10
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
s = ""
Print "排序后的数组为:"
For i = 1 To 10
s = s & a(i) & " "
Next i
Print s
End Sub
Private Sub Form_Load()
Dim str As String
str = "33,26,96,41,25,99,33,51,21,20"
a(1) = 33
a(2) = 26
a(3) = 96
a(4) = 41
a(5) = 25
a(6) = 99
a(7) = 33
a(8) = 51
a(9) = 21
a(10) = 20
End Sub