Logo Passei Direto
Buscar
Material

Prévia do material em texto

Chapter 1.2, Problem 4E Step-by-step solution Step 1 of 2 Finding the second smallest and smallest values in the array Consider an array of n integers. Traverse the array and keep track of the smallest as well as second smallest value in the traversed array. As we move further and if we find the value larger than second smallest then we will update our smallest value as well as second smallest value accordingly. Here input parameter is (array of integers) and Output parameters are second smallest as secondsmall Smallest as small value in array. Step 2 of 2 Algorithm: Finding the second smallest and smallest values in the array. array_small(s) small = [1] //will assigns first value to large sec ondsmall = s[2] while //traverse up to the end of array if sec //smaller value found if (s[i]

Mais conteúdos dessa disciplina