I am currently really stuck on how to solve the following problem:
struct node {
int a;
node* b;
}
I will have two root nodes without parents and then to more nodes pointing to their parents
vector<node> IholdAllTheNodes;
node noparent1; <--- these get returned from a method
node noparent2;
IholdAllTheNodes.pushback(noparent1);
IholdAllTheNodes.pushback(noparent2);
node withparent1; <---- i am happily points to noparent1
node withparent2; <-----i am happily points to noparent2
No problems up to here all working awesomely
IholdAllTheNodes.pushback(withparent1) <<<< oops this causes all the pointers to move.
now the withparent nodes are no longer pointing to their parents because I have moved them.
My question is simply how do I add more nodes to my vector of nodes without moving the pointers of the original nodes. (I cant get a fixed size for the vector)
if anyone has the time to explain, why even though pushback is adding to the end of the vector list is the location of the previous information changing?
aandb?push_back(). Your code can't even compile...