Decimal BASIC has two sorting libraries SORT1.LIB and SORT2.LIB.
SORT1.LIB contains an external subprogram sort(a()), which sort a one-dimensional array in increasing order.
When you use SORT1.LIB, add a MERGE statement at the tail of a program as shown in the following.
Example
10 DECLARE EXTERNAL SUB sort 20 DIM a(10) 30 DATA 3,8,4,6,9,2,5,5,7,5 40 MAT READ a 50 CALL sort(a) 60 MAT PRINT a; 70 END 80 MERGE "sort1.lib"
SORT2.LIB contains an external subprogram sort(m(),ix()), which assigns subscripts of an array m to an array ix in increasing order. That is, the first element of ix is the subscript of the smallest element of the array m. The array m shall not be changed.
Example
100 DECLARE EXTERNAL SUB sort 110 DIM a(10),ix(10) 120 DATA 3,8,4,6,9,2,5,5,7,5 130 MAT READ a 140 CALL sort(a,ix) 150 FOR i=1 TO 10 160 PRINT a(ix(i)); 170 NEXT i 180 END 190 MERGE "sort2.lib"