%
%	General Bubble Sort:
%		the comparison operation is a parameter.
%
procedure generalsort (var A: array 1..* of string, N:int,
		function greaterthan(a,b:string): boolean)
    var sorted: boolean

    for decreasing last: N..2
	sorted := true			% any interchanges this time?
	for i: 1..last-1
	    if greaterthan(A(i),A(i+1)) then	% interchange needed?
		sorted := false
		const foo := A(i)	% yes, do interchange
		A(i)   := A(i+1)
		A(i+1) := foo
	    end if
	end for
	exit when sorted
    end for
end generalsort
