某排序程序的主要代碼如下所示: n=5 For i=1 To n-1 For j=n-1 To i step-1 If d(j)<d(j+1)Then k=d(j):d(j)=d(j+1):d(j+1)=k Next j Next i 在排序過程中,某一遍排序后的結(jié)果是81,77,1,76,70,則下一遍排序后的結(jié)果應(yīng)該是( ?。?/h1>
是待排序的數(shù)據(jù),數(shù)據(jù)從a(1)開始存放;整數(shù)型參數(shù)n表示傳入的數(shù)組長度,該函數(shù)的返回值也是一個整數(shù)型數(shù)組.所以調(diào)用此函數(shù)實現(xiàn)排序非常方便: 比如有一個整數(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