Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tri Selection tri_selection([],[]). Tri_selection([X],[X]). tri_selection([X,Y|L],[Z|T]) :- minimum([X,Y|L],Z), retirer(Z,[X,Y|L], S) tri_selection(S,T).

Similar presentations


Presentation on theme: "Tri Selection tri_selection([],[]). Tri_selection([X],[X]). tri_selection([X,Y|L],[Z|T]) :- minimum([X,Y|L],Z), retirer(Z,[X,Y|L], S) tri_selection(S,T)."— Presentation transcript:

1 Tri Selection tri_selection([],[]). Tri_selection([X],[X]). tri_selection([X,Y|L],[Z|T]) :- minimum([X,Y|L],Z), retirer(Z,[X,Y|L], S) tri_selection(S,T). minimum([X],X). minimum([X,Y|L], X) :- minimum([Y|L],M), X =< M. minimum([X,Y|L], M) :- minimum([Y|L],M), X > M.

2 Retirer la première occ de X dans L retirer(X,[],[]). retirer(X,[X|L],L). retirer(X,[U|L],[U|M]):- X\==U, retirer(X,L,M).

3 Tri insertion triInser([],[]). triInser([X|L1],L2):- triInser(L1,L3), insererTri(X,L3,L2). insererTri(X,[],[X]). insererTri(X,[Y|L1],[Y|L2]):- X>Y, insererTri(X,L1,L2). insererTri(X,[Y|L1],[X,Y|L1]):- X=< Y.

4 partage(X,L,L1,L2). Spécification: Scinder la liste L en deux liste L1 et L2 tq éléments(L1)<=X < éléments(L2)

5 tri_rapide([],[]). tri_rapide([P|L],T):- partage(P,L,L1,L2), tri_rapide(L1,T1), tri_rapide(L2,T2), append(T1,[P|T2],T). partage(_,[],[],[]). partage(P,[X|T],[X|U1],U2):- P>X, partage(P,T,U1,U2). partage(P,[X|T],U1,[X|U2]):- P=<X, partage(P,T,U1,U2).


Download ppt "Tri Selection tri_selection([],[]). Tri_selection([X],[X]). tri_selection([X,Y|L],[Z|T]) :- minimum([X,Y|L],Z), retirer(Z,[X,Y|L], S) tri_selection(S,T)."

Similar presentations


Ads by Google