SORT

SmallBASIC syntax groups: 


Data command SORT


10
20  SORT array [USE cmpfunc]
30
Sorts an array. The cmpfunc if specified, takes 2 vars to compare and must return: -1 if x < y, +1 if x > y, 0 if x = y.


See examples


If there is insufficient information on this page and you wish learn more about SORT, please send an email to smallbasic@gmail.com. You can help to improve information about SORT by submitting an article using the comments link below. Note, an offline language reference text file is now avialable – see the Download section.

FUNC qscmp(x,y)
IF x=y
    qscmp=0
ELIF x>y
    qscmp=1
ELSE
    qscmp=-1
ENDIF
END
...
DIM A(5)
FOR i=0 TO 5
    A(i)=RND
NEXT
SORT A USE qscmp(x,y)