'===========================================================
'BasicSort 基本挿入方で整数をソートする
'---------引数----------------------------------------------
'data() ここのデータをソートする
'Count 要素の数
'flag True-昇順ソート,False-降順ソート
'===========================================================
Public Sub BasicSort(data() As Integer, Count As Integer, _
flag As Boolean)
Dim i As Integer, j As Integer
Dim temp As Integer
j = 1
If flag = False Then
Do While j < Count
i = j - 1
Do While i >= 0
If data(i + 1) < data(i) Then
temp = data(i + 1)
data(i + 1) = data(i)
data(i) = temp
Else
Exit Do
End If
i = i - 1
Loop
j = j + 1
Loop
Else
Do While j < Count
i = j - 1
Do While i >= 0
If data(i + 1) > data(i) Then
temp = data(i + 1)
data(i + 1) = data(i)
data(i) = temp
Else
Exit Do
End If
i = i - 1
Loop
j = j + 1
Loop
End If
End Sub
|