% \f(HDSorting:\fP can be done by iterated maximum finding
% As a first step, find the maximum in a list and put it at
% the head of the list.

const small := -1000000
const N: int := 100			% maximum names
var i: int  := 0
var imax: int  := 1			% index of maximum
var maximum: real := small	% start max off very small
var foo: real				% a dummy variable
var numbers : array 1 .. N of real

% First get the numbers.

put "Enter a list of numbers and I'll find the largest number"
loop
	get skip
	exit when eof or i >= N
	i := i + 1
	get numbers(i)
end loop

% Find the maximum

for j: 1..i
	if numbers(j) > maximum then
		maximum := numbers(j)
		imax    := j
	end if
end for

% We have our maximum, so now put it at the head of the list.

assert (i>0)
foo := numbers(1)
numbers(1) := numbers(imax)
numbers(imax) := foo

put "The partially sorted list is now"
for j: 1..i
	put numbers(j)
end for
