>
|
|
>
|
|
>
|
|
| (7) |
Calling the builtin procedure lexorder() directly is slower than using the 'lexorder' algorithm that is built in to sort().
>
|
|
>
|
|
>
|
|
Reversing the sense of the comparison is more costly still, because a full Maple procedure call is incurred for each comparison.
>
|
|
A better way to do this is to use a linear reversal algorithm after sorting the list with the builtin algorithm. Since sorting dominates at O(n*ln(n)), using the sorting algorithm with the smaller constant factor delivers better performance.
>
|
revsort := proc( los::list(string) )::list(string);
local L;
L := sort( los, 'lexorder' );
[ seq( L[ -i ], i = 1 .. nops( L ) ) ]
end proc:
|
>
|
|