06-10-2005, 09:43 PM
I have made comments to make it customizable. I want to make the comments as user friendly as possible. Please help me.
Code:
'The sub can use amax, amin, and array2() as optional values.
SUB qsort.integer.lowstart (array1() AS INTEGER, amax AS INTEGER)
DIM g2(1 TO 32) AS INTEGER, h2(1 TO 32) AS INTEGER 'Holds the ranges to sort and helps calculate pivot positions. This value should be at least log(UBOUND(array1)).
DIM e as INTEGER 'should be be able to hold at least log(UBOUND(array1)) + 1.
DIM i AS INTEGER, j AS INTEGER, r AS INTEGer, g AS INTEGER, h AS INTEGER 'These values should be able to hold a value of at least UBOUND(array1).
DIM k AS INTEGER 'this should be the same value as the array to sort. (array1())
e = 1
g2(1) = 1 'The starting position of the sort. Set it to LBOUND for the array min value.
h2(1) = amax 'The ending position of the sort. Set it to UBOUND for the array max value.
1
g = g2(e)
h = h2(e)
2 j = g: i = h: r = (g + h) \ 2: k = array1(r)
'to switch from a low to high order or vice versa, just switch these two signs:
'low to high:
'array1(j) < k
'array1(i) > k
'high to low:
'array1(j) > k
'array1(i) < k
3 IF array1(j) < k THEN j = j + 1: GOTO 3
4 IF array1(i) > k THEN i = i - 1: GOTO 4
IF j > i THEN GOTO 7
'To add an array linked to this one, swap it here too. ie: SWAP array2(i), array2(j)
SWAP array1(i), array1(j)
j = j + 1
i = i - 1
IF j > i THEN GOTO 7
GOTO 3
7
IF i + j < h + g THEN
IF j < h THEN g2(e) = j: h2(e) = h: e = e + 1
h = i
ELSE
IF g < i THEN g2(e) = g: h2(e) = i: e = e + 1
g = j
END IF
IF g < h THEN GOTO 2
e = e - 1
IF e THEN goto 1
ERASE g2, h2
END SUB
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Visit www.neobasic.net to see rubbish in all its finest.