I have a program in which I am trying to create a chain of (unspecified number) nodes. I want to be able to use a loop to create a new node and then link it in. I've tried it (and I think it works) to put the
new within the loop and just have the compiler allocate a new version of the variable using the same name.
E.g.,
- for ( )
-
Node * anode = new Node();
This doesn't seem to be the best way to do things.... I also tried creating an array of Node pointers beforehand and then doing the linking in a subsequent loop. Is there a more effective approach to this type of situation.
Thanks for any help. Sorry for not offering a more concrete example in the code.