配列変数をソート
配列変数の中身をソートします。
Option Explicit
Dim astrTest(3)
astrTest(0) = "Oxygen"
astrTest(1) = "Carbon"
astrTest(2) = "Nitorogen"
astrTest(3) = "Boron"
Call sbQuickSort(astrTest)
MsgBox astrTest(0)
MsgBox astrTest(1)
MsgBox astrTest(2)
MsgBox astrTest(3)
Sub sbQuickSort(astrWord)
If UBound(astrWord) < 0 Then
Exit Sub
End If
Call sbPrivateQuickSort(astrWord, 0, UBound(astrWord))
End Sub
Sub sbPrivateQuickSort(astrWord, iFst, iLst)
Dim strWord
Dim iFtp
Dim iLtp
Dim strTemp
strWord = astrWord(iFst)
iFtp = iFst
iLtp = iLst
Do
While (astrWord(iFtp) < strWord) : iFtp = iFtp + 1 : Wend
While (astrWord(iLtp) > strWord) : iLtp = iLtp - 1 : Wend
If iFtp >= iLtp Then Exit Do
strTemp = astrWord(iFtp)
astrWord(iFtp) = astrWord(iLtp)
astrWord(iLtp) = strTemp
iFtp = iFtp + 1
iLtp = iLtp - 1
Loop
If iFst < iFtp - 1 Then
Call sbPrivateQuickSort(astrWord, iFst, iFtp - 1)
End If
If iLtp + 1 < iLst Then
Call sbPrivateQuickSort(astrWord, iLtp + 1, iLst)
End If
End Sub