I'm trying to return the third highest number from a function by sending a 2D array created through smart pointers as a parameter but the problem is, I don't know how to do it. I have been searching through the internet for a possible solution but I couldn't seem to find one, Here's what I did,
int thirdhigh(int array[4][5])
{}
int main()
{
std::shared_ptr<std::shared_ptr<int[]>[]>array(new std::shared_ptr<int[]>[4]);//creates an array of pointers
//creates an array of size 5 and sends it addressess to the previous created array of pointers
for (int rows{ 0 }; rows < 4; ++rows) {
array[rows] = std::shared_ptr<int[]>(new int[5]);
}
//assigns random values to the 2D array created from 1-100
for (int r{ 0 }; r < 4; ++r) {
for (int c{ 0 }; c < 5; ++c) {
array[r][c] = ((rand() % 100) + 1);
}
}
//Shows the values assigned to the 2D array
for (int r{ 0 }; r < 4; ++r) {
for (int c{ 0 }; c < 5; ++c) {
std::cout << array[r][c] << "\t";
}
std::cout << std::endl;
}
//Returns the third highest number
thirdhigh(array[4][5]);
}
Also I need to use smart pointers only as I'm trying to learn it. Any suggestions would be helpful. Thanks!