A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Which of the following changes is needed for the program to work as intended?
A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Which of the following changes is needed for the program to work as intended?
Share
Answer is C, As is, the procedure traverses numberList from left to right and returns true whenever it encounters a value that is less than the preceding value. If it never encounters such a value, false is returned. This has the effect of returning true whenever the list is not increasing and returning false whenever the list is increasing, which is the opposite of what is intended. By interchanging lines 8 and 12, the procedure will return true or false appropriately.