Quicksort

defmodule Quicksort do
  def qsort([]) do
    []
  end
  
  def qsort([pivot | tail]) do
    qsort( lc x inlist tail, x < pivot, do: x ) ++ [pivot] ++ qsort( lc x inlist tail,x >= pivot, do: x )
  end
  
end


IO.puts inspect(Quicksort.qsort([10,9,1,3,5,6,4,2,8,7]))

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])



Casiano Rodriguez León 2015-01-07