!Ü4 *Y+Z ™+
!Ü 8 *X
™Q2
`
Select the VAR menu and start the program.
J%EXCO%
Minimum and Maximum Array Elements
This section contains two programs that find the minimum or maximum element of an array:
MNX uses a DO…UNTIL…END (indefinite) loop.
MNX2 uses a FOR…NEXT (definite) loop.
MNX (Minimum or Maximum Element—Version 1)
MNX finds the minimum or maximum element of an array on the stack.
Level 1 | → | Level2 | Level 1 |
|
|
|
|
[[ array ]] | → | [[ array ]] | Zmin or Zmax |
|
|
|
|
Techniques used in MNX
DO…UNTIL…END (indefinite loop). The DO clause contains the sort instructions. The UNTIL clause contains the
User and system flags for logic control:
User flag 10 defines the sort: When flag 10 is set, MNX finds the maximum element; when flag 10 is clear, it finds the minimum element. You determine the state of flag 10 at the beginning of the program.
System flag
Nested conditional. An IF…THEN…END conditional is nested in the DO…UNTIL…END conditional, and determines the following:
Whether to maintain the current minimum or maximum element, or make the current element the new minimum or maximum.
The sense of the comparison of elements (either < or >) based on the status of flag 10.
Custom menu. MNX builds a custom menu that lets you choose whether to sort for the minimum or maximum element. Key 1, labeled %MAX%, sets flag 10. Key 2, labeled %MIN%, clears flag 10.
Logical function. MNX executes XOR (exclusive OR) to test the combined state of the relative value of the two elements and the status of flag 10.