Erlang Central

Difference between revisions of "String Sort List"

From ErlangCentral Wiki

Line 22: Line 22:
[ free online casino slot]
[ casinos strategy]
[ casino games online]
[ slots tips]
[ online casino for cash]
[ Online casino - Poker in casino]
[ roulette description]
[ on line roulette game]
[ online casino net]
[ Gambling Online - Risks.]

Revision as of 12:54, 23 November 2006

Sorting a list of strings


You want to sort a list of strings.


Use the lists:sort operation to sort the lists. Note that by default sorting is case-sensitive. However, since you can use the lists:sort/2 variant of the function to supply your own sorting function this can be modified.

1> lists:sort(["foo", "bar", "baz", "qux"]).
2> lists:sort(fun(A, B) -> A =< B end, ["foo", "bar", "baz", "qux"]).
3> lists:sort(fun(A, B) -> A =< B end, ["foo", "bar", "baz", "qux"]).
4> lists:sort(fun(A, B) -> A >= B end, ["foo", "bar", "baz", "qux"]).

The sort operation uses the merge-sort algorithm, which takes time O(n log n) where n is the length of the list.