Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

Sorting an Icon list

Tech Computer Center logo

Icon's built-in ``sort()'' function can be used to order the elements of a list. The expression

    sort ( L )
returns a list with the same number of elements as L, except they are sorted. This makes sense only for certain types---integers, reals, and strings.

As an example, here is a program that writes the lines from its input in sorted order:

procedure main()
  lines  :=  [];   # Create an empty list
  while put ( lines, read ( ) );   # Store all lines
  every write ( ! sort ( lines ) ); # Sort and write
The second line reads each input line and adds it to the list. In the third line, the expression ``sort(lines)'' returns a list of the lines in sorted order; the ``!'' operator generates the lines from the sorted list in order, and then they are written to the output.
Next: Using the table type in Icon
See also: Using the list type in Icon
Previous: Generating the elements of an Icon list
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman,
Last updated: 1998/02/08 23:18:24 UT
QR two-dimensional bar code