Created
April 27, 2015 05:57
-
-
Save stochastic-thread/226dc7f0ae627847c91c to your computer and use it in GitHub Desktop.
Quicksort 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 Sorting do | |
def qsort(list) do | |
case list do | |
[] -> [] | |
_ -> | |
[h|t] = list | |
qsort(for n <- t, n < h, do: n) | |
++ [h] ++ | |
qsort(for n <- t, n >= h, do: n) | |
end | |
end | |
end | |
IO.inspect Sorting.qsort([10,123,443,2,3,2,1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment