Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,17 @@
defmodule Sort do
def bubble_sort(list) when length(list)<=1, do: list
def bubble_sort(list) when is_list(list), do: bubble_sort(list, [])
def bubble_sort([x], sorted), do: [x | sorted]
def bubble_sort(list, sorted) do
{rest, [max]} = Enum.split(bubble_move(list), -1)
bubble_sort(rest, [max | sorted])
end
def bubble_move([x]), do: [x]
def bubble_move([x, y | t]) when x > y, do: [y | bubble_move([x | t])]
def bubble_move([x, y | t]) , do: [x | bubble_move([y | t])]
end
IO.inspect Sort.bubble_sort([3,2,1,4,5,2])