Skip to content

Instantly share code, notes, and snippets.

@rbishop
Created September 26, 2014 17:49
Show Gist options
  • Save rbishop/c742ab53b12efc162176 to your computer and use it in GitHub Desktop.
Save rbishop/c742ab53b12efc162176 to your computer and use it in GitHub Desktop.
Quicksort in Elixir
# 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