Hi...
I had the following question.
I have a program findmax, that should determine recursively the maximum in an array. How can I call the function max correctly, so that I have the maximum of the array appearing on the screen?
I would appreciate any advice. Thank you in advance.
program findmax(input, output);
type
tIndex = 0..10;
tArray = array[tIndex] of integer;
const
Array : tArray = (1, 2, 3, 6, 3, 5, 9, 4 ,4 , 2, 1);
var
low,
high : integer;
function max(var inArray : tArray;
inLow,
inHigh : tIndex): integer;
var
middle : tIndex;
maxleft,
maxright : integer;
begin
if inLow = inHigh then
max := inArray[inLow]
else
begin
middle := (inLow + inHigh) div 2;
maxleft := max(inArray, inLow, middle);
maxright := max(inArray, middle+1, inHigh);
if maxleft > maxright then
max := maxleft
else
max := maxright
end
end;
begin
{????????}
readln
end.