|
QUICKSORT, aptly named, can be used to sort your arrays of any type, except
Objects/UDTs of course.
It, obviously, uses the QuickSort algorithm to perform the sort.
Syntax: QUICKSORT(Array-begin, Array-end, ASCEND|DESCEND)
DIM A(1000) AS INTEGER
'-- put stuff in A
QUICKSORT(A(10), A(500), ASCEND) '-- sorts elements 10..500
Details:
The pivot element in the above example is A(10), so if you want randomness,
you'll have to replace A(10) with some random element from A(10)..A(500) in the above
example. You can also sort multi-dimensional arrays and "span sort" arrays.
Span sorting:
DIM A(1 TO 100) AS LONG
DIM B(1 TO 100) AS LONG
DIM C(1 TO 100) AS LONG
'--- puts some values into array A, B, C
RANDOMIZE TIMER
FOR I = 1 TO 100
A(I) = RND(50000)
B(I) = RND(50000)
C(I) = RND(50000)
NEXT
QUICKSORT A(1), C(100), ASCEND
PRINT A(1)," ",B(1)," ",C(1)
As long as you DIM the arrays "side by side" they will share a contiguous
space of memory, this means you can sort from the start of memory address A(1)
to the end of memory address C(100). This technique is not recommended, but
if you can find a use for it, go ahead.
|