Created
October 27, 2013 13:23
-
-
Save parroty/7182043 to your computer and use it in GitHub Desktop.
Elixir QuickSort
This file contains 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
defmodule QuickSort do | |
def sort([]), do: [] | |
def sort([head|tail]) do | |
{lesser, greater} = Enum.partition(tail, &(&1 < head)) | |
sort(lesser) ++ [head] ++ sort(greater) | |
end | |
end | |
IO.inspect QuickSort.sort([1,6,3,4,2,5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment