C++ (data structure with c++). please send me copyable file Do not use an STL library functions to solve the following problem. A peak element of a 2d array of m rows and n columns is an element that...


C++ (data structure with c++). please send me copyable file


Do not use an STL library functions to solve the following problem.


A peak element of a 2d array of m rows and n columns is an element that is greater than any of its neighbors. There are 3 general cases:


the element is on an edge,


a[0][c] where 0


a[r][0] where 0


a[m – 1][c] where0


a[r][n – 1] where 0


the element is at a corner,


a[0][0]


a[0][n – 1]


a[m -1][0


a[m – 1][n – 1]


the element is an interior element,


a[x][y] where 0


The function, peaks, should return the number of peaks in a 2D array but it is missing a few statements. Complete the function.The function's prototype is


int peaks(int **a, int m, int n);


where a is a 2d integer array,


m is the number of rows in the array and n is the number of columns in the array.


program:


#include


#include


#include


#include


#include


using namespace std;


int** create(int nrows, int ncols)


{


if (nrows


return nullptr;


int** a2d = new int*[nrows];


for (int row = 0; row


a2d[row] = new int[ncols];


return a2d;


}


bool fill(int** a, int nrows, int ncols,


uniform_int_distribution& u,


default_random_engine& e)


{


if (nrows


return false;


for (int row = 0; row


for (int col = 0; col


a[row][col] = u(e);


return true;


}


void show(int** a, int nrows, int ncols)


{


for (int row = 0; row


{


for (int col = 0; col


cout


cout


}


}


int peaks(int** a, int nrows, int ncols)


{


return 0;


}


int main()


{


int nrows = 8;


int ncols = 8;


default_random_engine e;


uniform_int_distribution u(10, 99);


int** a2d = create(nrows, ncols);


fill(a2d, nrows, ncols, u, e);


show(a2d, nrows, ncols);


system("pause");


return 0;


}

Oct 25, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here