





















%   Purpose: a sorting routine which exploits existing order


samsort([], []) :

samsort(List, Sorted) :-
	samsort(List, [], 0, Sorted).

samsort([], Stack,
Sorted) :- !,
	samfuse(Stack, 0, [Sorted]).
samsort([Head|Tail], Stack, 
orted) :-
	sam_run(Tail, [Head|Queue], [Head|Queue], Run, Rest),
	su
, S),
	samfuse([Run|Stack], S, NewStack),
	samsort(Rest, NewStac
, Sorted).


samfuse([A,B|Rest], K, Ans)



















































































































