This sort also copes with the length issue of what would be variable length arrays in MS. The second parameter of the subroutine specifies the length: a caller set length independent of the real (but larger) length of the array. Or set it to a -1 length means the sort has to use the implicit 'count length' of the array.
=======Edited
Changed the script with respect to local vars. The sort script now restores the state of localvars to that when called
Code: Select all
SRT>arraySortNum
// calling format
// gosub>arraySortNum,myArray,-1 if length of array should be used
// or gosub>arraySortNum,myArray,myLen if length is specified, and lenth of array is not used. Part of array above myLen is not changed!
// and set all 9000 numbers to (largest number expected * 10) and upscale that number to let it start with a nine
// so if largest number is 800, then upscale 10*800 is 8000 to 9000
let>arraySortNum_VAR_lVar=LOCALVARS
let>LOCALVARS=0
if>arraySortNum_VAR_2<0
// set _n to [n] if that is the array format used, and 'exchange the 2 array references and the comments below
ArrayCount>arraySortNum_VAR_1,arraySortNum_VAR_L,_n
else>
let>arraySortNum_VAR_L=arraySortNum_VAR_2
Endif>
let>LOCALVARS=1
let>n=0
while>n<arraySortNum_VAR_L
let>n=n+1
// set all 9000 numbers to (largest number expected * 10) and upscale that number to let it start with a nine
let>localArray_%n%=%arraySortNum_VAR_1%_%n%+9000
// let>localArray_%n%=%arraySortNum_VAR_1[%n%]+9000
endwhile
arraySortNum>localArray
let>nn=0
while>nn<arraySortNum_VAR_L
let>nn=nn+1
let>LOCALVARS=0
let>%arraySortNum_VAR_1%_%nn%=localArray_%nn%-9000
// let>%arraySortNum_VAR_1[%nn%]=localArray_%nn%-9000
let>LOCALVARS=1
endwhile>
let>LOCALVARS=arraySortNum_VAR_lVar
END>arraySortNum
Code: Select all
// just code to test it, can be deleted
let>myArray_1=300
let>myArray_2=23
let>myArray_3=222
let>myArray_4=2
let>myArray_5=10
let>myArray_6=1
let>myArray_7=-300
let>myArray_8=-222
let>myArray_9=-2
let>myArray_10=-1
let>myArray_11=-10
let>myArray_12=999
let>myArray_13=-999
**BREAKPOINT**
gosub>arraySortNum,myArray,10
**BREAKPOINT**
gosub>arraySortNum,myArray,-1
**BREAKPOINT**