September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,9 +1,12 @@
|
|||
defmodule QuickSort do
|
||||
def qsort([]) do
|
||||
[]
|
||||
def qsort([]), do: []
|
||||
|
||||
def qsort([_|_] = list) do
|
||||
List.flatten do_qsort(list)
|
||||
end
|
||||
def qsort([pivot | rest]) do
|
||||
{ left, right } = Enum.partition(rest, fn(x) -> x < pivot end)
|
||||
qsort(left) ++ [pivot] ++ qsort(right)
|
||||
|
||||
defp do_qsort([pivot | rest]) do
|
||||
{left, right} = Enum.split_with(rest, &(&1 < pivot))
|
||||
[qsort(left), pivot, qsort(right)]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue