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
		       else
			  old max_val, old  i
		       end if;
   min_val, min_ind := if A[i] <  old min_val then
			  A[i], i
		       else
			  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


If you have any questions about this page, or want more information about the Sisal Language Project, contact:
John Feo at (510) 422-6389 or feo@diego.llnl.gov, or Tom DeBoni at (510) 423-3793 or deboni@llnl.gov.

The Sisal Language Project has been approved as a Designated Unclassified Subject Area (DUSA) K19222, as of 07 August, 1991.

LLNL Disclaimer
UCRL-MI-122601