Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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]

or the peak is the first element of an array,

a[1]

or the peak is the last element of the array.

a[size 2]

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

void peaks(int a[], int n, int p[], int &pcount);

where a is an integer array, n is an integer, p is an integer array, and pcount is an integer.

Desired Output:

image text in transcribed

//my code so far

#include  using namespace std; void peaks(int a[], int n, int p[], int &pcount); int main() { int a[] = {4, 3, 7, 1, 7}; int p[5], pcount; peaks(a, 5, p, pcount); cout  a[i+1]) { p[pcount++] = i; } } else if(i == n-1) { if (a[i] > a[i-1]) { p[pcount++] = i; } } else { if (a[i] > a[i-1] && a[i] > a[i+1]) { p[pcount++] = i; } } } } }

12 13 14 13 | 2 17 10 19 18|0 2 19 14 11 13 | 0 3 17 17 11 18 |3 18 16 14 10 | e 10 16 11 19 | 1 3 19 16 13 12 | 0 18 10 15 10 |0 2 12 17 18 17| 2 11 15 19 14 | 2 10 19 16 16 | 1 19 17 17 14 | 0 14 10 12 19 0 3 19 12 17 13 | 0 2 15 19 11 10 | 1 14 13 16 18 0 3 10 19 14 16 | 1 3 14 16 17 16 | 2 17 10 13 18 0 3 13 15 16 14| 2 14 14 14 16| 3 14 18 11 19 | 1 3 18 10 12 18 0 3 16 17 14 10| 1 10 18 13 10| 1 16 11 15 16 | 0 3 10 14 18 14 | 2 10 12 19 11 | 2 Press any key to continue 12 13 14 13 | 2 17 10 19 18|0 2 19 14 11 13 | 0 3 17 17 11 18 |3 18 16 14 10 | e 10 16 11 19 | 1 3 19 16 13 12 | 0 18 10 15 10 |0 2 12 17 18 17| 2 11 15 19 14 | 2 10 19 16 16 | 1 19 17 17 14 | 0 14 10 12 19 0 3 19 12 17 13 | 0 2 15 19 11 10 | 1 14 13 16 18 0 3 10 19 14 16 | 1 3 14 16 17 16 | 2 17 10 13 18 0 3 13 15 16 14| 2 14 14 14 16| 3 14 18 11 19 | 1 3 18 10 12 18 0 3 16 17 14 10| 1 10 18 13 10| 1 16 11 15 16 | 0 3 10 14 18 14 | 2 10 12 19 11 | 2 Press any key to continue

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

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions