06-15-2005, 11:50 PM
Hey guys,
Here's an example of a sort algorithm by Agamemnus which uses 5 precise goto's in the implementation of one of the fastest sort algorithms ever developed.You can probably remove the goto's and structure this code, but you will surely slow it down.
*****
Here's an example of a sort algorithm by Agamemnus which uses 5 precise goto's in the implementation of one of the fastest sort algorithms ever developed.
Code:
SUB AgaSort (amax AS INTEGER)
DIM g2(1 TO 32) AS INTEGER, h2(1 TO 32) AS INTEGER
DIM i AS INTEGER, j AS INTEGER, r AS INTEGER
DIM e AS INTEGER, g AS INTEGER, h AS INTEGER
REM DIM k AS INTEGER
DIM k AS INTEGER
e = 1
g2(1) = 1
h2(1) = amax
f1: g = g2(e): h = h2(e)
f2: i = g: j = h: r = (g + h) \ 2: k = Sortarray(r).length
f3: IF Sortarray(i).length < k THEN i = i + 1: GOTO f3
f4: IF Sortarray(j).length > k THEN j = j - 1: GOTO f4
IF i <= j THEN
IF i < j THEN SWAP Sortarray(i), Sortarray(j): SwapBars i, j
i = i + 1: j = j - 1
IF i <= j GOTO f3
END IF
IF j - g + i < h THEN
IF i < h THEN g2(e) = i: h2(e) = h: e = e + 1
h = j
ELSE
IF g < j THEN g2(e) = g: h2(e) = j: e = e + 1
g = i
END IF
IF g < h THEN GOTO f2
e = e - 1
IF e THEN GOTO f1
ERASE g2, h2
END SUB
*****