首页 > 解决方案 > 冒泡排序集合并忽略大小写敏感

问题描述

我正在使用冒泡排序对字符串列表进行排序。但是,如果我的列表中的一个是字符串开头的小写字母,它会将它放在列表的底部,即使该字母可能在中间。对获得预期输出有任何帮助吗?见下文:

List output:               expect output:

A                          A
B                          B
C                          C
K                          e
L                          K
e                          L

冒泡排序代码:

Public Function SortCollection(colInput As Collection) As Collection
Dim iCounter As Integer
Dim iCounter2 As Integer
Dim temp As Variant
 
Set SortCollection = New Collection
For iCounter = 1 To colInput.Count - 1
    For iCounter2 = iCounter + 1 To colInput.Count
        If colInput(iCounter) > colInput(iCounter2) Then
           temp = colInput(iCounter2)
           colInput.Remove iCounter2
           colInput.Add temp, temp, iCounter
        End If
    Next iCounter2
Next iCounter
Set SortCollection = colInput
End Function

标签: excelvba

解决方案


推荐阅读