Example Program: Insertion Sort
% Sorts through a large list of integers.
% Afterwards checks that the list is sorted.
% If is is outputs "PASS"
% Otherwise outputs "FAIL"
begin
var x,a,b,m,count:Integer
var array[0..2999]:Integer
proc insertionSort
begin
var i, value, j:Integer
i:=0
while i < 3000 do
begin
value:= array[i]
j:=i-1
while j >= 0 and array[j] > value do
begin
array[j+1] := array[j]
j:=j-1
end
array[j+1]:= value
i:= i + 1
end
end
func checkSorted:Boolean
begin
count:=1
while count<3000 do
begin
if(array[count-1] > array[count]) then
begin
return false
end
count:= count+1
end
return true
end
func mod(x:Integer, y:Integer):Integer
begin
while x >= y do
begin
x:=x-y
end
return x
end
x:=0
a:=4
b:=3
m:=1000
count:=0
while count<3000 do
begin
x:= mod((a*x + b), m)
array[count] := x
count:= count + 1
end
insertionSort
if(checkSorted) then write "PASS" else write "FAIL"
end