Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions