快速排序

只能针对整数排序

```

Public SubQSort2(ByRef key_arr()AsLong, LAsLong, RAsLong)

Dim i As Long, j As Long

Dim x AsLong, Swap As Long

Const k As Long = 60

If R - L <= k Then

For i = L +1 To R

            x = key_arr(i)


For j = i -1 To LStep-1

If key_arr(j) <= x Then Exit For

key_arr(j +1) = key_arr(j)

Next

key_arr(j +1) = x

Next

Else

x = key_arr((L + R) \2)

        i = L

        j = R

Do Whilei <= j

Do Whilekey_arr(i) < x

i = i +1

Loop


Do While key_arr(j) > x

j = j -1

Loop


If i <= j Then

                Swap = key_arr(i)

                key_arr(i) = key_arr(j)

                key_arr(j) = Swap

i = i +1

j = j -1

End If

Loop

'递归方法

If L < j Then

Do While key_arr(j) = x

j = j -1

If j = L Then Exit Do

Loop

Call QSort2(key_arr, L, j)

End If

If i < R Then

Do While key_arr(i) = x

i = i +1

If i = R Then Exit Do

Loop

Call QSort2(key_arr, i, R)

End If

End If

End Sub

```

你可能感兴趣的:(快速排序)