Created
September 26, 2014 17:49
-
-
Save rbishop/c742ab53b12efc162176 to your computer and use it in GitHub Desktop.
Quicksort in Elixir
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
# Not tail recursive and uses ++ :( | |
defmodule Quicksort do | |
def sort([]), do: [] | |
def sort([head | rest]) do | |
{before, after} = Enum.partition(rest, &(&1 < head)) | |
sort(before) ++ [head] ++ sort(after) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment