sort_array(3) LPC Library Functions sort_array(3)
NNAAMMEE
sort_array() - sort an array
SSYYNNOOPPSSIISS
mixed *sort_array( mixed *arr, string fun, object ob );
mixed *sort_array( mixed *arr, int direction );
DDEESSCCRRIIPPTTIIOONN
The first form returns an array with the same elements as
`arr', but quicksorted in ascending order according to the
rules in `ob->fun()'. `ob->fun()' will be passed two
arguments for each call. It should return -1, 0, or 1,
depending on the relationship of the two arguments
(lesser, equal to, greater than).
Here are two common forms for the compare function to
take:
int compare(string one, two) {
return strcmp(one, two);
}
int compare(int one, two) {
return (one - two);
}
The second form returns an array with the same elements as
'arr', but quicksorted using built-in sort routines. A
'direction' of 1 or 0 will quicksort in ascending order,
while a 'direction' of -1 will quicksort in descending
order. A limitation of the built-in sort routines is that
the array must be homogeneous, composed entirely of a sin-
gle type, where that type is string, int, or float.
SSEEEE AALLSSOO
filter_array(3), map_array(3), strcmp(3)
MudOS 5 Sep 1994 1