% Referencias:
%   http://ktiml.mff.cuni.cz/~bartak/prolog/sorting.html
%   https://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_7.html
%   http://200.17.141.213/~gutanunes/hp/IA/prolog_palazzo.pdf


%-------------------------
% ORDENACAO BOLHA

bubble_sort(List,Sorted) :- b_sort(List,[],Sorted).
b_sort([],Acc,Acc).
b_sort([H|T],Acc,Sorted) :- bubble(H,T,NT,Max), b_sort(NT,[Max|Acc],Sorted).
   
bubble(X,[],[],X).
bubble(X,[Y|T],[Y|NT],Max) :- X > Y, bubble(X,T,NT,Max).
bubble(X,[Y|T],[X|NT],Max) :- X =< Y, bubble(Y,T,NT,Max).
