Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→{{header|Icon}}: note on mixed type sorting
m (→{{header|Icon}}: fix sortop) |
(→{{header|Icon}}: note on mixed type sorting) |
||
Line 943:
The following code supports this and other sorting demonstrations.
* Sorting illustrates a difference in the way Icon and Unicon handles data types. Built-in operators for comparing data types make a syntactic distinction between numeric and string types, and sorting structured and user-defined types require custom code.
* The 'sortop' procedure allows various methods of comparison be selected including customized ones. The example could be made more general to deal with coercion of types like cset to string (admittedly an uninteresting example as csets are already sorted). Custom comparators are shown by and example procedure 'cmp'.
* 'demosort' can apply different sorting procedures and operators to lists and strings to show how this works. The routines 'displaysort' and 'writex' are helpers.
|