Inserting elements into 2D vector

后端 未结 3 634
遥遥无期
遥遥无期 2021-01-18 06:44

so I\'m creating a class that implements an adjacency list. Currently in my class definition I initialized two vectors:

vector> adjLi         


        
3条回答
  •  渐次进展
    2021-01-18 06:52

    If initially you do not have any values in the vector - You can push values into one vector and then push this vector into the 2D vector. For example:

      vector< vector > vt1;
      vector vt2;
    
      vt2.push_back(value);
      vt1.push_back(vt2);
    

    If your vector is already populated then -

    vt1[index].push_back(value);
    

提交回复
热议问题