Created
August 2, 2012 09:38
-
-
Save nobrinskii/3235906 to your computer and use it in GitHub Desktop.
配列をクイックソートする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------------------------ | |
'配列をクイックソート | |
'------------------------------------------------------------------------------ | |
'【引数】配列(参照渡し)、最小インデックス、最大インデックス | |
'【戻り値】 | |
'【備考】 | |
Public Sub Q_Sort(ByRef varArray() As Variant, _ | |
lngMini As Long, lngMax As Long) | |
Dim i As Long | |
Dim j As Long | |
Dim varBaseValue As Variant | |
Dim varTmp As Variant | |
varBaseValue = varArray(Int((lngMini + lngMax) / 2)) | |
i = lngMini | |
j = lngMax | |
Do | |
Do While varArray(i) < varBaseValue | |
i = i + 1 | |
Loop | |
Do While varArray(j) > varBaseValue | |
j = j - 1 | |
Loop | |
If i >= j Then Exit Do | |
varTmp = varArray(i) | |
varArray(i) = varArray(j) | |
varArray(j) = varTmp | |
i = i + 1 | |
j = j - 1 | |
Loop | |
If (lngMini < i - 1) Then | |
Call Q_Sort(varArray, lngMini, i - 1) | |
End If | |
If (lngMax > j + 1) Then | |
Call Q_Sort(varArray, j + 1, lngMax) | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment