Commit 70e90bfd authored by Ilya Prokhorov's avatar Ilya Prokhorov

Pre bubble sort implementation in erlang

parent dfce91ae
-module(bubbleSort).
-export([start/0]).
startBubbleSort([CurrentHead|Tail]) ->
compareHeads(CurrentHead, Tail, []).
compareHeads(CurrentHead, [NextHead|Tail], []) ->
io:fwrite("---\n"),
io:format("CurrentHead: ~w~n", [CurrentHead]),
io:format("NextHead: ~w~n", [NextHead]),
compareHeads(NextHead, Tail, [CurrentHead]);
compareHeads(CurrentHead, [NextHead|Tail], [OutputListHead|OutputListTail]) ->
io:fwrite("---\n"),
io:format("CurrentHead: ~w~n", [CurrentHead]),
io:format("NextHead: ~w~n", [NextHead]),
OutputList = lists:append([[OutputListHead], OutputListTail, [CurrentHead]]),
compareHeads(NextHead, Tail, OutputList);
compareHeads(CurrentHead, [], [OutputListHead|OutputListTail]) ->
io:fwrite("---\n"),
OutputList = lists:append([[OutputListHead],OutputListTail, [CurrentHead]]),
io:format("OutputList: ~w~n", [OutputList]),
io:fwrite("End\n").
start() ->
UnsortedList = [4,7,1,2,9,10],
startBubbleSort(UnsortedList).
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment