Question: Need done in C++ A peak element of an array of n elements is an element at a position i such that a[i - 1]

Need done in C++

A peak element of an array of n elements is an element at a position i such that

a[i - 1] < a[i] and a[i + 1] < a[i] where 0 < i < size - 1.

or the peak is the first element of an array,

a[1] < a[0]

or the peak is the last element of the array.

a[size 2] < a[size [ size - 1]

Write and test thoroughly a function that returns the number of peaks in an array of n elements. The function's prototype is

int peaks(int a[], int n);

where a is an integer array and n is an integer.

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 Databases Questions!