Różnice

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

Odnośnik do tego porównania

pl:prolog:pllib:interchange_sort [2019/06/27 15:50]
pl:prolog:pllib:interchange_sort [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Interchange sort ======
 +{{tag>​sorting algorithms}}
 +===== Description =====
 +Sorting by Interchange
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{interchange_sort.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +    mysort(Xs,​Ys) :- 
 + Ys is an ordered permutation of the list of integers Xs.
 +*/
 +    mysort(Xs,​Ys) :-
 + append(As,​[X,​Y|Bs],​Xs),​
 + X > Y,
 + !,
 + append(As,​[Y,​X|Bs],​Xs1),​
 + mysort(Xs1,​Ys).
 +    mysort(Xs,​Xs) :-
 + ordered(Xs),​ !.
 +
 + ordered([]).
 + ordered([X]).
 + ordered([X,​Y|Ys]) :- X =< Y, ordered([Y|Ys]).
 +
 +%  Program 11.5   ​Interchange sort
 +
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/interchange_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