Różnice

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

Odnośnik do tego porównania

pl:prolog:pllib:reverse_no_duplicate [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Reverse no duplicate ======
 +{{tag>​lists}}
 +===== Description =====
 +Reversing with no duplicates
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{reverse_no_duplicate.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +     ​nd_reverse(Xs,​Ys) :- 
 + Ys is the reversal of the list obtained by 
 + removing duplicate elements from the list Xs.
 +*/
 +     ​nd_reverse(Xs,​Ys) :- nd_reverse(Xs,​[],​Ys).
 +
 +     ​nd_reverse([X|Xs],​Revs,​Ys) :-
 + member(X,​Revs),​ nd_reverse(Xs,​Revs,​Ys).
 +     ​nd_reverse([X|Xs],​Revs,​Ys) :-
 + nonmember(X,​Revs),​ nd_reverse(Xs,​[X|Revs],​Ys).
 +     ​nd_reverse([],​Ys,​Ys).
 +
 +     ​nonmember(X,​[Y|Ys]) :- X \== Y, nonmember(X,​Ys).
 +     ​nonmember(X,​[]).
 +
 +%  Program 7.10   ​Reversing with no duplicates
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/reverse_no_duplicate.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