11 lines
249 B
Text
11 lines
249 B
Text
mergesort([],[]). % special case
|
|
mergesort([A],[A]).
|
|
mergesort([A,B|R],S) :-
|
|
split([A,B|R],L1,L2),
|
|
mergesort(L1,S1),
|
|
mergesort(L2,S2),
|
|
merge(S1,S2,S).
|
|
|
|
split([],[],[]).
|
|
split([A],[A],[]).
|
|
split([A,B|R],[A|Ra],[B|Rb]) :- split(R,Ra,Rb).
|