Есть ответ на http://en.literateprograms.org/Bubble_sort_%28Erlang%29
-module(bubblesort).
-export([sort/1]).
-import(lists, [reverse/1]).
sort(L) -> sort(L, [], true).
sort([], L, true) -> reverse(L);
sort([], L, false) -> sort(reverse(L), [], true);
sort([ X, Y | T ], L, _) when X > Y ->
sort([ X | T ], [ Y | L ], false);
sort([ X | T ], L, Halt) -> sort(T, [ X | L ], Halt).
Пример сортировки 2,4,3,5,1
сортировка ([2,4,3,5,1])
раунд 1
=> sort ([2,4,3,5,1], [], true)
=> sort ([4, 3,5,1], [2], true)
=> sort ([4,5,1], [3,2], false)
=> sort ([5,1], [4,3,2], false)
=> sort ([5], [1,4,3,2], false)
=>sort ([], [5,1,4,3,2], false)
=> sort ([2,3,4,1,5], [], true)
round 2
=> sort ([3,4,1,5], [2], true)
=> sort ([4,1,5], [3, 2], true)
=> sort ([4,5], [1,3,2], false)
=> sort ([5], [4,1, 3,2], false)
=> sort ([], [5,4,1,3,2], false)
=> sort ([2,3,1,4,5], [], true)
round 3
=> sort ([3,1,4,5], [2], true)
=> sort ([3,4,5], [1,2], false)
=> sort ([4,5], [3,1,2], false)
=> sort ([5], [4,3,1,2], false)
=> sort ([], [5,4,3,1,2], false)
=> сортировать ([2,1,3,4,5]true)
round 4
=> sort ([2,3,4,5], [1], false)
=> sort ([3,4,5], [2,1], false)
=> sort ([4,5], [3,2,1], false)
=> sort ([5], [4,3,2,1], false)
=> sort ([], [5,4,3,2,1], false)
=>sort ([1,2,3,4,5], [], true)
round 5
=> sort ([2,3,4,5], [1], верно)
=> сортировать ([3,4,5], [2,1], верно)
=> сортировать ([4,5], [3,2,1], true)
=> sort ([5], [4,3,2,1], true)
=> sort ([], [5,4,3, 2,1], верно)
=> [1,2,3,4,5]