Lists merging

Description

Merging lists with cuts

Source: The Art of Prolog

Download

Program source code: lists_merging.pl

Listing

/*
   mymerge(Xs,Ys,Zs) :- 
	Zs is an ordered list of integers obtained from merging
	the ordered lists of integers Xs and Ys.
*/
     mymerge([X|Xs],[Y|Ys],[X|Zs]) :-
	X < Y, !, mymerge(Xs,[Y|Ys],Zs).
     mymerge([X|Xs],[Y|Ys],[X,Y|Zs]) :-
	X =:= Y, !, mymerge(Xs,Ys,Zs).
     mymerge([X|Xs],[Y|Ys],[Y|Zs]) :-
	X > Y, !, mymerge([X|Xs],Ys,Zs).
     mymerge(Xs,[],Xs) :- !.
     mymerge([],Xs,Xs) :- !.
 
%  Program 11.2    Merging with cuts

Comments

pl/prolog/pllib/lists_merging.txt · ostatnio zmienione: 2017/07/17 08:08 (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