Ticket #59: merge.pl

File merge.pl, 223 bytes (added by ke, 8 years ago)
Line 
1merge([X|Xs],[Y|Ys],[X|Zs]) :-
2  X < Y,
3  merge(Xs,[Y|Ys],Zs).
4merge([X|Xs],[Y|Ys],[X,Y|Zs]) :-
5  X =:= Y,
6  merge(Xs,Ys,Zs).
7merge([X|Xs],[Y|Ys],[Y|Zs]) :-
8  X > Y,
9  merge([X|Xs],Ys,Zs).
10merge(Xs,[],Xs).
11merge([],Ys,Ys).