vusjtq
Last Updated: February 25, 2016
·
1.525K
· edgurgel
5e0f65b214819fedf529220e19c08908

Quicksort in Elixir

defmodule Quick do
  def sort([]), do: []
  def sort([pivot | rest]) do
    { left, right } = Enum.partition(rest, &(&1 < pivot))
    sort(left) ++ [pivot | sort(right)]
  end
end
iex> Quick.sort [5, 4, 3, 2, 1]
[1, 2, 3, 4, 5]

http://elixir-lang.org/

Say Thanks
Respond