T
Tony
Hello,
For my application, I have a vector containing data that I need,
vector<NODE> node_data; and I have a pointer of vectors which are
sorted by some criterion as vector<NODE*> np. I have planned the data
management as:
Whenever I want to add a new node, I push_back onto the end of
node_data and create a corresponding reference in np. However, I find
that only the last-added pointer in np correctly points to the right
location in memory of the NODE elements. My suspicion is that when
vector increases its size in memory, it completely reallocates a
larger space in memory such that the old references are no longer
valid. Is this true? i.e. when increasing the size of a vector, a
completely new structure is created in memory rather than just
"tacking on" an additional element at the end?
If I wanted to be able to leave the old information alone, and
actually just "tack on" something at the end, would the List be a
better choice?
Finally, could I get some suggestions for a "casual" book on
algorithms (as far as casual they can be!) for a hobbyist programmer?
Thank you very much
For my application, I have a vector containing data that I need,
vector<NODE> node_data; and I have a pointer of vectors which are
sorted by some criterion as vector<NODE*> np. I have planned the data
management as:
Whenever I want to add a new node, I push_back onto the end of
node_data and create a corresponding reference in np. However, I find
that only the last-added pointer in np correctly points to the right
location in memory of the NODE elements. My suspicion is that when
vector increases its size in memory, it completely reallocates a
larger space in memory such that the old references are no longer
valid. Is this true? i.e. when increasing the size of a vector, a
completely new structure is created in memory rather than just
"tacking on" an additional element at the end?
If I wanted to be able to leave the old information alone, and
actually just "tack on" something at the end, would the List be a
better choice?
Finally, could I get some suggestions for a "casual" book on
algorithms (as far as casual they can be!) for a hobbyist programmer?
Thank you very much