Skip to content

Instantly share code, notes, and snippets.

@fenprace
Created June 1, 2013 15:43
Show Gist options
  • Save fenprace/5690796 to your computer and use it in GitHub Desktop.
Save fenprace/5690796 to your computer and use it in GitHub Desktop.
My quick sort
-module(QS).
-export([quick_sort/1]).
quick_sort([]) -> [];
quick_sort([X]) -> [X];
quick_sort([X, Y]) ->
if
X =< Y -> [X, Y];
X > Y -> [Y, X]
end;
quick_sort(List) ->
[Mid | _] = List,
Left = lists:filter(fun(E) -> E < Mid end, List),
Middle = lists:filter(fun(E) -> E == Mid end, List),
Right = lists:filter(fun(E) -> E > Mid end, List),
lists:append(lists:append(quick_sort(Left), Middle), quick_sort(Right)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment