是待排序的數(shù)據(jù),數(shù)據(jù)從a(1)開(kāi)始存放;整數(shù)型參數(shù)n表示傳入的數(shù)組長(zhǎng)度,該函數(shù)的返回值也是一個(gè)整數(shù)型數(shù)組.所以調(diào)用此函數(shù)實(shí)現(xiàn)排序非常方便: 比如有一個(gè)整數(shù)型數(shù)組a(1 to 10)需要降序排序,可以直接這樣調(diào)用: a
=bubble_sort(False,a
,10) 該函數(shù)VB代碼如下: Function bubble_sort(sx As Boolean,a
As Integer,n As Integer) As Integer
Dim i,j,t As Integer For i=1 To n-1 For j=
Step-1 If
Then If a(j)<a(j-1)Then t=a(j):a(j)=a(j-1):a(j-1)=t Else 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 bubble_sort=a