c++ - Inserting elements into 2D vector -


so i'm creating class implements adjacency list. in class definition initialized 2 vectors:

vector<vector<int>> adjlist; vector<int> neighbors; 

and declared 2 functions plan use make it:

bool constructadjlist(); bool insertintoadjlist(int, int); 

it's getting difficult wrapping head around 2d vectors. understand vector of vectors, i'm confused how insert new value 1 of "subvectors". example, able create adjacency list in createadjlist empty following loop:

for (int = 0; < numofvalues; i++){     neighbors.push_back(0);     adjlist.push_back(neighbors);     neighbors.clear(); } 

but how can say, push_back value 5 4th vector in adjlist, represented in insertintoadjlist function

insertintoadjlist(4, 5); 

i know can access specific value in 2d vector saying adjlist[4][1], how can push 1 onto it?

thanks!

to push on vector element of vector, this

adjlist[x].push_back(); 

Comments

Popular posts from this blog

javascript - Wordpress slider, not displayed 100% width -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -