user2946312
user2946312

Reputation:

Find max value and delete that row in 2D array. C++

I need to work with two random 2D arrays. For example one is 5x10. I can find max value in matrix, but I don`t know how to delete that row, where this max value is!

int max_ind(int masivs[x][y], int a, int b, int row[y], int rinda)
{
    max=masivs[0][0];
    for(i=0;i<a;i++)
        for(j=0;j<b;j++)
            if (masivs[i][j]>max)
                max=masivs[i][j];
    printf("%7d\n",max);
}

Any ideas?

Upvotes: 0

Views: 1564

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409176

Save the row index too, and not only the maximum value, and after the loops remove that row.

Oh, and it will be much simpler to remove a row if you use e.g. std::vector (like std::vector<std::vector<int>> masivs).


If you can't use std::vector, then you have to move the remaining rows and decrease the row count by one. This can be done by a loop that move the next row into the "max" row, the next-next row to the next row, and so on.

Upvotes: 1

Related Questions