Syntax
Sorts a list of numbers or strings, in place.
SortList(<list>(), <options> [, <start>, <end>])Parts
| <list> | A list declared with NewList, written with its empty parentheses: scores(). |
|---|---|
| <options> | Required. #AK_ORDER_LOW_TO_HIGH (0), #AK_ORDER_HIGH_TO_LOW (1), and #AK_ORDER_FOLD_CASE (2) to ignore the case of letters. Add them to combine: 3 sorts from high to low and ignores case. |
| <start> | Optional. The position of the first element to sort, from 0. |
| <end> | Optional, required with <start>. The position of the last element to sort, included. |
Good to know
- Returns nothing: write it on its own line.
- After the sort there is no current element. Call FirstElement() or ResetList() before reading
a(). - Without
#AK_ORDER_FOLD_CASE, strings compare by character code: every capital letter comes before every small one. - SortList(a()) alone is a compile error: the options are required. Any other value stops the program with "Unknown BASIC SortList option".
- Without
<start>and<end>, the whole list is used. Giving only<start>compiles but stops the program with "BASIC collection range requires start and end". A range outside the list stops it with "BASIC collection range is out of bounds". - A list of records stops the program with "SortList requires a primitive typed list": use SortStructuredList().
Example
NewList a.integer()FOR k = 1 TO 4 AddElement(a()) a() = Mod(k * 7, 5)NEXTSortList(a(), #AK_ORDER_HIGH_TO_LOW)FOREACH a() Console(Str(a())) ' 4, 3, 2, 1NEXTIn the manual : Arrays, lists and maps