Categories
Erlang

A Quicksort in Erlang

qsort([]) -> [];
qsort([Pivot|T]) ->
   qsort([X || X <- T, X < Pivot])    ++ [Pivot] ++    qsort([X || X <- T, X >= Pivot]).

%% Let L be a list of unsorted numbers.
%% 2> L=[234,322,233,5,1000].
%% [234,322,233,5,1000]
%%
%% 3> lib_misc:qsort(L).
%%
%% qsort will return:
%% [5,233,234,322,1000]

Leave a Reply

Your email address will not be published. Required fields are marked *