Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
% msort( L, S )
|
||||
% True if S is a sorted copy of L, using merge sort
|
||||
msort( [], [] ).
|
||||
msort( [X], [X] ).
|
||||
msort( U, S ) :- split(U, L, R), msort(L, SL), msort(R, SR), merge(SL, SR, S).
|
||||
|
||||
% split( LIST, L, R )
|
||||
% Alternate elements of LIST in L and R
|
||||
split( [], [], [] ).
|
||||
split( [X], [X], [] ).
|
||||
split( [L,R|T], [L|LT], [R|RT] ) :- split( T, LT, RT ).
|
||||
|
||||
% merge( LS, RS, M )
|
||||
% Assuming LS and RS are sorted, True if M is the sorted merge of the two
|
||||
merge( [], RS, RS ).
|
||||
merge( LS, [], LS ).
|
||||
merge( [L|LS], [R|RS], [L|T] ) :- L =< R, merge( LS, [R|RS], T).
|
||||
merge( [L|LS], [R|RS], [R|T] ) :- L > R, merge( [L|LS], RS, T).
|
||||
Loading…
Add table
Add a link
Reference in a new issue