04-04-2005, 07:15 PM
A simple recursive Quicksort compiled in FB 0.13 took 3,3 seconds in my PC (P4 2.4Mhz) to order the 3M elements.
It's said recursion is slow..I have somewhere a nonrecursive quicksort that should be faster.
I have no PBCC to compare.
Code:
Sub Quicksort(min,max)
dim p1,p2,midd as string*7
IF min < max THEN
p1 = min
p2 = max
midd = Myarray((min + max) \ 2)
DO UNTIL p1 > p2
DO WHILE Myarray(p1) < midd
p1 = p1 + 1
LOOP
DO WHILE midd < Myarray(p2)
p2 = p2 - 1
LOOP
IF p1 <= p2 THEN
SWAP Myarray(p1), Myarray(p2)
p1 = p1 + 1
p2 = p2 - 1
END IF
LOOP
IF min < p2 THEN Quicksort min, p2
IF p1 < max THEN Quicksort p1, max
END IF
end sub
I have no PBCC to compare.
Antoni