快速排序

只能针对整数排序

```

Public SubQSort2(ByRefkey_arr()AsLong, LAsLong, RAsLong)

DimiAsLong, jAsLong

DimxAsLong, SwapAsLong

ConstkAsLong=60

IfR - L <= kThen

Fori = L +1ToR

            x = key_arr(i)


Forj = i -1ToLStep-1

Ifkey_arr(j) <= xThenExitFor

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

DoWhilei <= j

DoWhilekey_arr(i) < x

i = i +1

Loop


DoWhilekey_arr(j) > x

j = j -1

Loop


Ifi <= jThen

                Swap = key_arr(i)

                key_arr(i) = key_arr(j)

                key_arr(j) = Swap

i = i +1

j = j -1

EndIf

Loop

'递归方法

IfL < jThen

DoWhilekey_arr(j) = x

j = j -1

Ifj = LThenExitDo

Loop

CallQSort2(key_arr, L, j)

EndIf

Ifi < RThen

DoWhilekey_arr(i) = x

i = i +1

Ifi = RThenExitDo

Loop

CallQSort2(key_arr, i, R)

EndIf

EndIf

EndSub

```

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