Skip to content

Instantly share code, notes, and snippets.

@traverse
Created October 12, 2016 09:51
Show Gist options
  • Save traverse/aca9b9f934cd1ed4c2905bed74baa10e to your computer and use it in GitHub Desktop.
Save traverse/aca9b9f934cd1ed4c2905bed74baa10e to your computer and use it in GitHub Desktop.
Quicksort implemented in Erlang
quicksort([]) -> [];
quicksort([P|R]) ->
{S,L} = partition(P,R,[],[]),
quicksort(S) ++ [P] ++ quicksort(L).
partition(_,[],S,L) -> {S,L};
partition(P,[H|T],S,L) ->
if H =< P -> partition(P,T,[H|S],L);
H > P -> partition(P,T,S,[H|L])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment