03-07-2003, 10:55 PM

Ok, you asked for it:

The eight-line iterative quicksort (minus the array creation and printing).

ph34r mY l33t c0|)iNG 5KiLL5!

:rotfl: :rotfl:

The eight-line iterative quicksort (minus the array creation and printing).

Code:

`'initialize an array.`

a.max% = 50: DIM array1(a.max%) AS INTEGER

'generate random numbers

RANDOMIZE TIMER

CLS : FOR i% = 1 TO a.max%: array1(i%) = INT(RND * 5000) + 1: NEXT i%

1 DIM g2%(a.max% / 2), h2%(a.max% / 2), g3%(a.max% / 2), h3%(a.max% / 2): e% = 1: f% = 0: g2%(1) = 0: h2%(1) = a.max%

2 FOR d% = 1 TO e%: g% = g2%(d%): h% = h2%(d%): i% = 0: j% = 0: k% = 0: IF g% >= h% THEN GOTO 8 ELSE IF h% > g% THEN GOTO 3: IF array1(g%) <= array1(h%) THEN GOTO 3: SWAP array1(g%), array1(h%): GOTO 8

3 SWAP array1(h%), array1(INT(RND * (h% - g% + 1)) + g%): k% = array1(h%)

4 i% = g%: j% = h%

5 IF i% < j% AND array1(i%) <= k% THEN i% = i% + 1: GOTO 5

6 IF j% > i% AND array1(j%) >= k% THEN j% = j% - 1: GOTO 6 ELSE IF i% < j% THEN SWAP array1(i%), array1(j%): GOTO 4 ELSE SWAP array1(i%), array1(h%)

7 IF i% + i% - g% < h% THEN f% = f% + 1: g3%(f%) = g%: h3%(f%) = i% - 1: f% = f% + 1: g3%(f%) = i% + 1: h3%(f%) = h% ELSE f% = f% + 1: g3%(f%) = i% + 1: h3%(f%) = h%: f% = f% + 1: g3%(f%) = g%: h3%(f%) = i% - 1

8 NEXT d%: FOR i% = 1 TO f%: g2%(i%) = g3%(i%): h2%(i%) = h3%(i%): NEXT i%: e% = f%: f% = 0: IF e% <> 0 THEN GOTO 2

'print it

PRINT "Final sorted array: ": PRINT

FOR i% = 1 TO a.max%: PRINT array1(i%); : NEXT i%

ph34r mY l33t c0|)iNG 5KiLL5!

:rotfl: :rotfl: