in a certain other language (that i am not going to mention

) there was a command to sort arrays
however, i don't think it has to be copied as such

but we might learn from it
before sorting, i'd prefer a SwapElement() command, which would allow easier implementation of other self built sorting algoritms (which i have no problem with by itself

):
Code: Select all
syntax: SwapElement( [ list() , ] n1.l , n2.l )
example:
SwapElement(testlist(),10,20)
SwapElement(10,20)
also, i would love to be able to address elements directly instead of going via SelectElement:
Code: Select all
SelectElement(10)
list() = whatever
list(10) = whatever
i would have no problem with a more simple sort command, that would sort the linked list based upon its contacts, without taking care of the fields... for simple lists that would do great, there is some influence over the way of sorting when defining your structs, it's fast to implement, and fancy stuff could always be done by hand
i guess most of us do mostly simple sorts, this would already be a great help
(no, i'm not going to mention something similar for arrays... oh, hi fred

)
Code: Select all
SortListUp( [ list() ] )
SortListDown( [ list() ] )
how it's done elsewhere (reference only, disclaimer etc. etc. etc.

)
Code: Select all
SSORT Function
Action: sorts the elements in an array by its size using the Shell-Metzner algorithm.
Syntax: SSORT x(s)[,n][,m%()]
SSORT x$(s) [WITH n()][OFFSET o][,n[,m%()]]
s: + or - for ascending or descending order
n,o: iexp
x(): one dimensional array
x$(): one dimensional string array
n(): one dimensional integer array with 1,2 or 4 byte variables
m%(): one dimensional integer array with 4 byte variables
Explanation: The s enclosed in round brackets can be replaced with a "+", a "-" or it may be left out. "+" or no
specification results in arrays x() and m%() being sorted in ascending order. In this case, after the sorting,
the smallest array element assumes the smallest index (0 for OPTION BASE 0 or 1 for OPTION BASE 1).
"-" results in the array being sorted in descending order. In this case, after the sorting, the biggest array
element assumes the smallest index.
The parameter n specifies that only the first n elements of the array should be sorted. For OPTION BASE
0 these are the elements with indices 0 to "n"-1, and for OPTION BASE 1 the elements with indices 1 to
"n". If n is given explicitly, it can be followed by a LONG integer array, which will be sorted together with
the array x(), that is to say, each swap in array x() will also be performed in array m%(). This is particularly
useful when the sorted array x() contains the sort key (for example the postal code), while other arrays
contain the additional information whose information must maintain the same order as the keys.
When sorting string arrays (x$()) a sort criterion can be specified with WITH, in form of an array n() with at
least 256 elements. If WITH is not given the normal ASCII table is used as the sort criterion.
Optionally, OFFSET o can specify the number of characters at the start of the string to ignore during
sorting.