Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
quicksort set
#24
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.
Reply


Messages In This Thread
quicksort set - by Agamemnus - 11-22-2003, 11:46 PM
quicksort set - by relsoft - 11-23-2003, 01:03 PM
quicksort set - by Agamemnus - 11-23-2003, 08:27 PM
quicksort set - by Mango - 12-19-2003, 09:36 PM
quicksort set - by Agamemnus - 12-19-2003, 10:48 PM
quicksort set - by Mango - 12-19-2003, 11:07 PM
quicksort set - by Agamemnus - 12-20-2003, 08:52 AM
quicksort set - by adosorken - 12-20-2003, 09:04 AM
quicksort set - by Agamemnus - 12-20-2003, 09:23 AM
quicksort set - by adosorken - 12-20-2003, 09:32 AM
quicksort set - by Mango - 12-20-2003, 09:46 AM
quicksort set - by adosorken - 12-20-2003, 06:07 PM
quicksort set - by Agamemnus - 12-20-2003, 08:56 PM
quicksort set - by Agamemnus - 06-03-2005, 07:37 PM
quicksort set - by Torahteen - 06-03-2005, 08:01 PM
quicksort set - by Agamemnus - 06-03-2005, 10:15 PM
quicksort set - by Torahteen - 06-03-2005, 10:44 PM
quicksort set - by Agamemnus - 06-03-2005, 10:51 PM
quicksort set - by Moneo - 06-03-2005, 11:17 PM
quicksort set - by Torahteen - 06-04-2005, 01:04 AM
quicksort set - by Agamemnus - 06-04-2005, 01:14 AM
quicksort set - by TheBigBasicQ - 06-07-2005, 01:35 AM
quicksort set - by Agamemnus - 06-10-2005, 06:50 PM
quicksort set - by Agamemnus - 06-10-2005, 09:43 PM
quicksort set - by Ralph - 06-14-2005, 08:21 PM
quicksort set - by MystikShadows - 06-14-2005, 11:23 PM
quicksort set - by SBM Productions - 07-13-2005, 10:22 PM
quicksort set - by Ralph - 07-14-2005, 03:48 AM
quicksort set - by Moneo - 07-15-2005, 11:50 PM
quicksort set - by rpgfan3233 - 07-16-2005, 01:31 AM
quicksort set - by yetifoot - 12-07-2005, 08:40 AM
quicksort set - by Agamemnus - 12-07-2005, 10:01 AM
quicksort set - by Ralph - 12-07-2005, 08:29 PM
quicksort set - by Mango - 12-08-2005, 06:21 AM
quicksort set - by Agamemnus - 12-09-2005, 04:53 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)