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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started