Question: c++ In a 1D array, a peak is a number that is greater that the 2 numbers adjacent to it and valley is a number

c++

In a 1D array, a peak is a number that is greater that the 2 numbers adjacent to it and valley is a number that is less than the2 numbers adjacent to it. The first element and last elements in an array are adjacent.

Suppose the array is1 9 3 4 6 2 8 5

1 is a valley because it is less than 9 and is less than 5

9 is peak

3 is a valley

4 is neither a peak nor a valley

6 is a peak

2 is a valley

8 is a peak

5 is neither a peak nor a valley because it less than 8 but is greater than 1

test a function returns the number of peaks and valleys in a array. Do not use any global variables or global constants to write the function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!