Prévia do material em texto
Chapter 1.2, Problem 5E Step-by-step solution Step 1 of 2 Finding the largest and smallest values in an array of integers Consider an array of n integers. Traverse the array and keep track of the smallest as well as largest value in the traversed array. As we move further and if we find the value smaller than smallest then we will update our smallest value as well if we find the value larger than the largest then we will update our largest value accordingly. Here, input parameter is (array of integers) Output parameters are smallest as small and largest value as large in the array. Step 2 of 2 Algorithm: Finding the largest and smallest values in an array of integers. array_min_large(s) small = s[1] //will assigns first value to small large = s[1] //will assigns first value to large i = 2 //traverse up to the end of array //smallest value in traversed array found here small = // new small > large) large = s[i] //new large } return small and large }