Exercise 7.2: First Maximum and Minimum Loop

Given: a one-dimensional array, A, of real values;
Compose: a for-initial loop that finds the first instance of the minimum and maximum values present in the array, and returns these values and their index positions.
for initial
   i := array_liml(A);
   max_val := A[i];
   min_val := A[i];
   max_ind := i;
   min_ind := i;
while i < array_limh(A) repeat
   i := old i + 1;
   max_val, max_ind := if A[i] >  old max_val then
			  A[i], i
			  old max_val, old  i
		       end if;
   min_val, min_ind := if A[i] <  old min_val then
			  A[i], i
			  old min_val, old  i
		       end if;
returns value of max_val
	value of max_pos
	value of min_val
	value of min_ind
end for 

Previous Section