|
楼主 |
发表于 2015-4-11 08:43
|
显示全部楼层
wangfeng0918 发表于 2015-4-10 21:21
升级准备看一下源码,可惜作者没有放出来啊?
附件包里面有,直接贴个源码吧。不过里面的快排不好。- Public Sub ZSort(Olda(), Newa(), ParamArray c())
- 'Olda():为排序数组
- 'Newa():为存放结果数组
- 'ParamArray c():传递排序参数数组,奇数个为排序列号,偶数为升降序,0或者省略为升序
- Dim P() As Long, w() As Long, B() As Boolean
- Dim i&, j&, k&, n1&, n2&, nb&, ne&
- k = UBound(c)
- If k = -1 Then
- ReDim P(1)
- P(0) = 1
- Else
- If k Mod 2 Then ReDim P(k) Else ReDim P(k + 1)
- For i = 0 To k
- P(i) = c(i)
- Next
- End If
- n1 = LBound(Olda)
- n2 = UBound(Olda)
- ReDim w(n1 To n2)
- ReDim B(n1 To n2)
- For i = n1 To n2
- w(i) = i
- Next
- If P(1) = 0 Then QSort Olda, w, P(0), n1, n2 Else QSort2 Olda, w, P(0), n1, n2
- For i = 2 To k Step 2
- nb = n1
- ne = n1
- While ne < n2
- Do
- ne = ne + 1
- If ne > n2 Then Exit Do
- Loop Until B(ne) Or Olda(w(ne), P(i - 2)) <> Olda(w(ne - 1), P(i - 2))
- If ne - nb > 1 Then
- If P(i + 1) = 0 Then QSort Olda, w, P(i), nb, ne - 1 Else QSort2 Olda, w, P(i), nb, ne - 1
- End If
- If ne <= n2 Then B(ne) = True
- nb = ne
- Wend
- Next
- For i = n1 To n2
- For j = 1 To UBound(Newa, 2)
- Newa(i, j) = Olda(w(i), j)
- Next
- Next
- End Sub
- Private Sub QSort(R(), w() As Long, Key&, L&, H&)
- Dim i&, j&, x, y
- i = L
- j = H
- x = R(w(L + 1 + Int((H - L - 1) * Rnd)), Key)
- While (i <= j)
- While (R(w(i), Key) < x And i < H)
- i = i + 1
- Wend
- While (x < R(w(j), Key) And j > L)
- j = j - 1
- Wend
- If (i <= j) Then
- y = w(i)
- w(i) = w(j)
- w(j) = y
- i = i + 1
- j = j - 1
- End If
- Wend
- If (L < j) Then QSort R, w, Key, L, j
- If (i < H) Then QSort R, w, Key, i, H
- End Sub
- Private Sub QSort2(R(), w() As Long, Key&, L&, H&)
- Dim i&, j&, x, y
- i = L
- j = H
- x = R(w(L + 1 + Int((H - L - 1) * Rnd)), Key)
- While (i <= j)
- While (R(w(i), Key) > x And i < H)
- i = i + 1
- Wend
- While (x > R(w(j), Key) And j > L)
- j = j - 1
- Wend
- If (i <= j) Then
- y = w(i)
- w(i) = w(j)
- w(j) = y
- i = i + 1
- j = j - 1
- End If
- Wend
- If (L < j) Then QSort2 R, w, Key, L, j
- If (i < H) Then QSort2 R, w, Key, i, H
- End Sub
复制代码 |
|