Public Function sort(ByVal a() As Integer)
Dim temp As Integer
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
Return 0
End Function
追问要求用byref啊
追答Public Function sort(ByRef a() As Integer)
Dim temp As Integer
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
Return 0
End Function
追问为什么循环都是1 to10呢😳
万一数组元素有20个😳
呢
追答Public Function sort(ByRef a() As Integer)
Dim temp As Integer
Dim x As Integer
x = UBound(a)
For i = 1 To x
For j = 1 To x - 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
Return 0
End Function