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