mardi 14 février 2023

How To get size of varying cols in rows of a 2d vector?

How do you find the size of an individual row in a 2d matrice in which all the rows vary in size. So its not a NxM matrice rather they're all a little different in length.

vector<vector<int>> &someVector;
vector<int> v;
resV.resize(10);

for(int i = 0; i < 10; i++)
{
    for(int j = 0; j < (int)someVector.size(); j++) //iterates through all the rows
        if(!(someVector[i][j] <= 0) ) // i represents the row and j the col it is at
            .push_back(someVector[i][j]); // adds value into 1d vector
}

I used this code here because i know the columns length of 1 row wont exceed 10. It psuhes it into another vector which is of 1 row so it will be easier to print out and find its mid value which is something different that will be easy once i can get the values of this 2d vector into the 1d vector.

This code here results in an error on the 2nd for loop line.

Aucun commentaire:

Enregistrer un commentaire