このディレクトリの索引
このディレクトリの索引

%% TECHINIQUES OF PROLOG PROGRAMMING by T. Van Le, ph D.  %%

selection_sort([],[]).
selection_sort(L,[H|T]) :-
    least(H,L,R),
    selection_sort(R,T).

least(X,L,R) :-
    select(X,L,R),
    smaller(X,R).

smaller(_,[]).
smaller(X,[H|T]) :-
    X =< H,
    smaller(X,T).

select(H,[H|T],T).
select(X,[H|T],[T|T1]) :- select(X,T,T1).