vector of an array?

Started by
9 comments, last by csxpcm 20 years, 6 months ago
I would use a vector of vector pointer to node.

vector< vector< node >* > levels;

vector< node >* tmp = new vector;
tmp->push_back(node(1,1,''b'',1));
levels.push_back(tmp);
tmp = new vector;
tmp->push_back(node(2,2,''g'',1));
levels.push_back(tmp);
tmp = new vector;
tmp->push_back(node(3,5,''h'',1));
levels.push_back(tmp);
tmp = new vector;
tmp->push_back(node(4,5,''w'',1));
levels.push_back(tmp);
tmp = new vector;
tmp->push_back(node(5,3,''p'',1));
levels.push_back(tmp);

Then you can go

levels[2]->[0] which give you the first node in 3 vector which is node for (3,5,''h'',1)
add you can add node to level[2]->push_back()

Or if you would like to use the [] like in java maybe do a map of vector of node

map< int, vector< nodes > * > levels;
then you can do something like this
levels[2] = new vector< node >;
levels[2]->push_back(node(3,5,''h'',1));

map give you a [] like vector back is not as fast as vector since a map is realy a sorted tree. BBut it allows you to not have to have 0, 1 vector of a node before you do a 2 like above example.

Lord Bart

This topic is closed to new replies.

Advertisement