Definition: | sequence s2 = sort(sequence s1, integer order=ASCENDING) |
Description: |
Sort s1 into ascending order using a fast sorting algorithm. The elements of s1 can be any mix of atoms or sequences.
Atoms come before sequences, and sequences are sorted "alphabetically" where the first elements are more significant
than the later elements, and with case sensitively (whereby 'Z' is before 'a').
The builtin constants ASCENDING and DESCENDING should be used for the order parameter, if required. That parameter was added for compatibility with OpenEuphoria, and likewise the constants NORMAL_ORDER and REVERSE_ORDER, which are (as per OpenEuphoria) just aliases for ASCENDING and DESCENDING respectively, and therefore behave identically. For a case-insensitive sort, see "Another Example" in tagset(). |
Example 1: |
x = 0 & sort({7,5,3,8}) & 0 -- x is set to {0, 3, 5, 7, 8, 0} |
Example 2: |
y = sort({"Smith", "Jones", "Doe", 5.5, 4, 6}) -- y is {4, 5.5, 6, "Doe", "Jones", "Smith"} |
Example 3: |
database = sort({{"Smith", 95.0, 29}, {"Jones", 77.2, 31}, {"Clinton", 88.7, 44}}) -- The 3 database "records" will be sorted by the first "field" -- i.e. by name. Where the first field (element) is equal it -- will be sorted by the second field etc. -- after sorting, database is: {{"Clinton", 88.7, 44}, {"Jones", 77.2, 31}, {"Smith", 95.0, 29}} |
See Also: | custom_sort, compare, match, find |