Common Array Algorithms
7. Minimum and Maximum
Answer:
array = new int[ size ];
Minimum and Maximum
The largest integer in a list of integers is the maximum value. The maximum may occur several times, but no other integer in the list is larger. Look at the following:
2, 9, 52, 23, -19, 23, 17, -45, 0
The integer 52 is the maximum. If you plot these integers on a number line the maximum is the last one on the right.
Similarly, the smallest integer in the list is the minimum. The minimum may occur several times. In the above list, the minimum is -45. The minimum is the last number on the left of the number line.
Question 7:
Examine the following collection of integers:
-20, 19, 1, 27, 5, -1, 27, 19, 5
- What is the maximum of the collection?
- How did you figure this out?