# 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 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:

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.

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).

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.

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)

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= { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/12/3697177/slides/slide_5.jpg", "name": "tri_rapide([],[]).", "description": "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=

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