0
我使用冒泡排序功能通過其屬性的對象進行排序。不幸的是,我必須爲每個屬性編寫一個函數。有什麼辦法來概括下面的功能。冒泡排序的對象?
而不是寫
SortArticlesByVolume(a)
SortArticlesByLenght(a)
的,我想寫出類似:
SortArticles(a, volume)
子SortArticlesByVolume(爲ByRef文章爲Variant)
Dim sorted As Boolean
Dim i As Integer
sorted = False
Do While Not sorted
sorted = True
For i = 0 To UBound(articles) - 1
If articles(i).volume < articles(i + 1).volume Then
Set temp = articles(i + 1)
Set articles(i + 1) = articles(i)
Set articles(i) = temp
sorted = False
End If
Next i
Loop
末次
子SortArticlesBylenght(文章爲ByRef爲Variant)
Dim sorted As Boolean
Dim i As Integer
sorted = False
Do While Not sorted
sorted = True
For i = 0 To UBound(articles) - 1
If articles(i).lenght < articles(i + 1).lenght Then
Set temp = articles(i + 1)
Set articles(i + 1) = articles(i)
Set articles(i) = temp
sorted = False
End If
Next i
Loop
末次
'lenght',真的嗎? – 2012-03-26 14:57:20