展开全部
'冒泡排序,最简单的排序算法,下面这个子过程是对Integer类型的数组升序排序,如果需要其他类型的数据,可以将其中的Integer替换掉
Sub MaoPaoSort(a() As Integer)
Dim i As Integer
Dim j As Integer
Dim temp As Integer
For i = LBound(a()) To UBound(a()) - 1
For j = LBound(a()) To UBound(a()) - 1
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next
Next
End Sub
Sub MaoPaoSort(a() As Integer)
Dim i As Integer
Dim j As Integer
Dim temp As Integer
For i = LBound(a()) To UBound(a()) - 1
For j = LBound(a()) To UBound(a()) - 1
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next
Next
End Sub
展开全部
Private Sub Command1_Click()
Dim a(20) As Integer
For i = 1 To 20
a(i) = Int(100 * Rnd)
Print a(i);
Next i
Call sort(a, 20)
Print "排序以后:"
For i = 1 To 20
Print a(i);
Next i
End Sub
Sub sort(a() As Integer, n As Integer)
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Sub s(arr&())
Dim i%, j%, l%, n%, tmp&
l = LBound(arr)
n = UBound(arr)
For i = l + 1 To n
For j = n To i Step -1
If arr(j) < arr(j - 1) Then
tmp = arr(j)
arr(j) = arr(j - 1)
arr(j - 1) = tmp
End If
Next
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询