Created
January 30, 2017 07:04
-
-
Save ympons/9ad44750c7253dfabd7a29b0b50a3b08 to your computer and use it in GitHub Desktop.
Simple QuickSort implementation 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
defmodule QuickSort do | |
def sort([]), do: [] | |
def sort([head|tail]) do | |
{l, r} = Enum.partition(tail, &(&1 > head)) | |
sort(l) ++ [head] ++ sort(r) | |
end | |
end | |
a = QuickSort.sort([3, 1, 2, 5]) | |
IO.inspect a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment