sort

sort — sorts a list or array, destructively modifying the order.

Syntax

sort (list_or_array, compare_function)
		

Arguments

list_or_array

A list or an array.

compare_function

A function on two arguments used to compare elements in the list or array.

Returns

The input list or array, sorted.

Description

This function sorts the list or array in place, destructively modifying the order of the elements. The compare_function must be a function on two arguments which returns: an integer value less than zero if the first argument is ordinally less than the second, zero if the two arguments are ordinally equal, and greater than zero if the first argument is ordinally greater than the second. This function uses the quicksort algorithm.

Example

Gamma> x = list("one","two","three","four","five");
("one" "two" "three" "four" "five")
Gamma> sort(x,strcmp);
("five" "four" "one" "three" "two")
Gamma> x;
("five" "four" "one" "three" "two")
Gamma>