Finding unique elements of a list
Thomas Johnsson XA (LN/EAB)
thomas.xa.johnsson@REDACTED
Fri Dec 3 08:45:49 CET 2004
In other functional languages I've used (Haskell, (Lazy) ML,..), I've often used the following variation of quicksort when representing sets as sorted lists without duplicates:
(This is Erlang syntax, not Haskell..:-)
mkset([M|Xs]) ->
mkset([X||X<-Xs,X<M])++[M]++mkset([X||X<-Xs,X>M]);
mkset([]) ->
[].
Cute, if I may say so myself (:-), but unfortunately O(n^2) when the argument
already is a sorted list :-(
Erlang has lists:usort, which presumably does the same thing,
hopefully more efficiently. (?)
-- Thomas
More information about the erlang-questions
mailing list