[erlang-questions] Bubble sort in Erlang

Pierpaolo Bernardi olopierpa@REDACTED
Sun May 20 06:46:35 CEST 2007

On 5/19/07, Milen Dzhumerov <gamehack@REDACTED> wrote:
> Hi all,
> I've recently picked up the "Programming Erlang" book and started
> experimenting with Erlang. So I wanted to implement some toy
> algorithms - would you believe me that I was kind of stuck for
> several days on the train while going to work implementing a simple
> bubble sort algorithm?

The following is the most straightforward implementation of bubblesort
I could come up with:



sort(List) ->
    case bubble_pass(List) of
        {Res,true} -> Res;
        {Res,false} -> sort(Res)

%% bubble_pass(List) -> {Bubbled,Done}.

bubble_pass([]) ->
bubble_pass([A]) ->
bubble_pass([A|Rest]) ->
    {[B|T],Done} = bubble_pass(Rest),
    if A =< B ->
       true ->



More information about the erlang-questions mailing list