Skip to content

Instantly share code, notes, and snippets.

@vKxni
Created November 18, 2022 21:09
Show Gist options
  • Save vKxni/050d094608756fefc885ac0338f07de6 to your computer and use it in GitHub Desktop.
Save vKxni/050d094608756fefc885ac0338f07de6 to your computer and use it in GitHub Desktop.
Sorting Alg Vol. 1
-module(list_sort).
-export([main/0]).
main() ->
L = lists:map(fun(_) -> rand:uniform(1000) end, lists:seq(1, 1000)),
Sorted = bubble_sort(L),
io:format("~p~n", [Sorted]).
bubble_sort(L) ->
bubble_sort(L, []).
bubble_sort([], Sorted) ->
Sorted;
bubble_sort([H | T], Sorted) ->
bubble_sort(T, insert(H, Sorted)).
insert(X, [H | T]) when X > H ->
[H | insert(X, T)];
insert(X, L) ->
[X | L].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment