Created
June 1, 2013 15:43
-
-
Save fenprace/5690796 to your computer and use it in GitHub Desktop.
My quick sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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