Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:permutation_sort [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Permutation sort ======
 +{{tag>​sorting algorithms recursion}}
 +===== Description =====
 +Permutation sort
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{permutation_sort.pl}}
 +===== Listing =====
 +<code prolog>
 +/*        
 + sort(Xs,​Ys) :- 
 + The list Ys is an ordered permutation of the list Xs.
 +*/
 +
 + sort(Xs,​Ys) :- permutation(Xs,​Ys),​ ordered(Ys).
 +
 + permutation(Xs,​[Z|Zs]) :- select(Z,​Xs,​Ys),​ permutation(Ys,​Zs).
 + permutation([],​[]).
 +
 + ordered([]).
 + ordered([X]).
 + ordered([X,​Y|Ys]) :- X =< Y, ordered([Y|Ys]).
 +
 + select(X,​[X|Xs],​Xs).
 + select(X,​[Y|Ys],​[Y|Zs]) :- select(X,​Ys,​Zs).
 +
 +% Program 3.20 Permutation sort
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/permutation_sort.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0