另一个算法,同容相同,写法不同而已
#include <array.au3>
local $array[100];=[3,8,7,1,2,5,6,4,44,2,11,35,93,22,12]
for $i=0 to 99
$array[$i]=Random(1,10000,1)
Next
$timer=TimerInit()
quicksort($array,0,99)
;_ArraySort($array)
_arraydisplay($array,TimerDiff($timer))
func quicksort(ByRef $arr,$beg=0,$end=0)
If $End <= $beg Then Return
If $End < 1 Or $End > UBound($arr)-1 Then $End = UBound($arr)-1
If $beg < 0 Then $beg = 0
If $beg > $End Then Return SetError(2, 0, 0)
local $key=$arr[$beg]
local $l=$beg
local $h=$end
While $l<$h
while $key<=$arr[$h] and $l<$h
$h-=1
WEnd
$arr[$l]=$arr[$h]
while $arr[$l]<=$key and $l<$h
$l+=1
WEnd
$arr[$h]=$arr[$l]
WEnd
$arr[$l]=$key
$l+=1
quicksort($Arr, $beg, $h)
quicksort($Arr, $l, $end)
EndFunc
|