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

    var inserted: boolean
    var next: string

    for s : 2..N			% A(1..s-1) are sorted
	next := A(s)
	inserted := false
	for decreasing pos: s..2	% find place to insert
	    if greaterthan(next,A(pos-1)) then
		A(pos)   := next
		inserted := true
		exit
	    else
		A(pos) := A(pos-1)	% shift element one down
	    end if
	end for

	if not inserted then
	    A(1) := next
	end if
    end for
end generalsort
