% 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 POR INSERCAO

insert_sort(List,Sorted) :- i_sort(List,[],Sorted).
i_sort([],Acc,Acc).
i_sort([H|T],Acc,Sorted) :- insert(H,Acc,NAcc), i_sort(T,NAcc,Sorted).
   
insert(X,[Y|T],[Y|NT]) :- X > Y, insert(X,T,NT).
insert(X,[Y|T],[X,Y|T]):- X =< Y.
insert(X,[],[X]).
