level 3
G自在W
楼主
Sub QuickSort(MyArray(,) As String, Contrast As Long, StartInt As Long, EndInt As Long, LenInt As Long, Optional Order As Boolean = True)
Dim i As Integer, j As Integer, M As Single
Dim TempShzu(100) As String
i = StartInt
j = EndInt
'找出数组的中点
M = MyArray((StartInt + EndInt) / 2, Contrast)
If Order = True Then '按照顺序排列
While (i <= j)
'找出比中点大的数
While (MyArray(i, Contrast) < M And i < EndInt)
i = i + 1
End While
'找出比中点小的数
While (M < MyArray(j, Contrast) And j > StartInt)
j = j - 1
End While
'互换这两个数
If (i <= j) Then
For p = 0 To LenInt
TempShzu(p) = MyArray(i, p)
MyArray(i, p) = MyArray(j, p)
MyArray(j, p) = TempShzu(p)
Next p
i = i + 1
j = j - 1
End If
End While
'未完成时递归调用
If (StartInt < j) Then Call QuickSort(MyArray, Contrast, StartInt, j, LenInt, True)
If (i < EndInt) Then Call QuickSort(MyArray, Contrast, i, EndInt, LenInt, True)
Else '按照倒叙排列
While (i <= j)
'找出比中点大的数
While (MyArray(i, Contrast) > M And i < EndInt)
i = i + 1
End While
'找出比中点小的数
While (M > MyArray(j, Contrast) And j > StartInt)
j = j - 1
End While
'互换这两个数
If (i <= j) Then
For p = 0 To LenInt
TempShzu(p) = MyArray(i, p)
MyArray(i, p) = MyArray(j, p)
MyArray(j, p) = TempShzu(p)
Next p
i = i + 1
j = j - 1
End If
End While
'未完成时递归调用
If (StartInt < j) Then Call QuickSort(MyArray, Contrast, StartInt, j, LenInt, False)
If (i < EndInt) Then Call QuickSort(MyArray, Contrast, i, EndInt, LenInt, False)
End If
End Sub
--调用的时候
QuickSort (你的数组,第几列用来对比,数组起始数字,数组结束数字,数组横向长度,是否正向排序)
例如 dim shuzu(100,15) as string
...数组内容省略...
其中第12列是用来对比的 shuzu(变量,12)
函数:
QuickSort (shuzu,12,0,100,15,true)
本算法搜索自百度,因不好用,自己稍微改了一下.
2015年10月20日 14点10分
1
Dim i As Integer, j As Integer, M As Single
Dim TempShzu(100) As String
i = StartInt
j = EndInt
'找出数组的中点
M = MyArray((StartInt + EndInt) / 2, Contrast)
If Order = True Then '按照顺序排列
While (i <= j)
'找出比中点大的数
While (MyArray(i, Contrast) < M And i < EndInt)
i = i + 1
End While
'找出比中点小的数
While (M < MyArray(j, Contrast) And j > StartInt)
j = j - 1
End While
'互换这两个数
If (i <= j) Then
For p = 0 To LenInt
TempShzu(p) = MyArray(i, p)
MyArray(i, p) = MyArray(j, p)
MyArray(j, p) = TempShzu(p)
Next p
i = i + 1
j = j - 1
End If
End While
'未完成时递归调用
If (StartInt < j) Then Call QuickSort(MyArray, Contrast, StartInt, j, LenInt, True)
If (i < EndInt) Then Call QuickSort(MyArray, Contrast, i, EndInt, LenInt, True)
Else '按照倒叙排列
While (i <= j)
'找出比中点大的数
While (MyArray(i, Contrast) > M And i < EndInt)
i = i + 1
End While
'找出比中点小的数
While (M > MyArray(j, Contrast) And j > StartInt)
j = j - 1
End While
'互换这两个数
If (i <= j) Then
For p = 0 To LenInt
TempShzu(p) = MyArray(i, p)
MyArray(i, p) = MyArray(j, p)
MyArray(j, p) = TempShzu(p)
Next p
i = i + 1
j = j - 1
End If
End While
'未完成时递归调用
If (StartInt < j) Then Call QuickSort(MyArray, Contrast, StartInt, j, LenInt, False)
If (i < EndInt) Then Call QuickSort(MyArray, Contrast, i, EndInt, LenInt, False)
End If
End Sub
--调用的时候
QuickSort (你的数组,第几列用来对比,数组起始数字,数组结束数字,数组横向长度,是否正向排序)
例如 dim shuzu(100,15) as string
...数组内容省略...
其中第12列是用来对比的 shuzu(变量,12)
函数:
QuickSort (shuzu,12,0,100,15,true)
本算法搜索自百度,因不好用,自己稍微改了一下.