From Cryos · 1996-04-08 05:25 · #63190 in Bar Mat (Tech Help)
SLiNkEY got caught in the information superparkinglot, and started chatting to everyone :
S> Anyone know any good, fast sort routines? I currently use this type
S> (1 of only two ways I know) ...
That's my favourite - slow, but it works :)
S> 200, in ARexx things tend to slow done with this sort code and I need
S> something faster.
I usedta love ARexx, but this Pi$$y doesn't do it :(
Anyway, this is in BASIC, coz it's been a coupla years since I did ARexx, and I'd bollux it up if I tried... Dunno how this works, but it's damn fast :)
SUB QuickSort (Low, High)
IF Low < High THEN
IF High - Low = 1 THEN
IF SortArray(Low).Length > SortArray(High).Length THEN
SWAP SortArray(Low), SortArray(High)
END IF
ELSE
RandIndex = RandInt%(Low, High)
SWAP SortArray(High), SortArray(RandIndex)
Partition = SortArray(High).Length
DO
I = Low: J = High
DO WHILE (I < J) AND (SortArray(I).Length <= Partition)
I = I + 1
LOOP
DO WHILE (J > I) AND (SortArray(J).Length >= Partition)
J = J - 1
LOOP
IF I < J THEN
SWAP SortArray(I), SortArray(J)
END IF
LOOP WHILE I < J
SWAP SortArray(I), SortArray(High)
IF (I - Low) < (High - I) THEN
QuickSort Low, I - 1
QuickSort I + 1, High
ELSE
QuickSort I + 1, High
QuickSort Low, I - 1
END IF
END IF
END IF
END SUB
.--.
: .--'
: : .--. .-..-. .--. .--.
: :__ : ..': :; :' .; :`._-.'
`.__.':_; `._. ;`.__.'`.__.' @cryos.ooh.dircon.co.uk
.-. :
`._.'
... "Bother," said Pooh, as Roger Cook knocked on the door again.
--- FMail/386 1.02
* Origin: The Wall (959:100/42.15)