Storing a tree in a std::list<>

From: Dave (better_cs_now_at_yahoo.com)
Date: 06/06/04


Date: Sat, 5 Jun 2004 15:57:59 -0700


Hello all,

After perusing the Standard, I believe it is true to say that once you
insert an element into a std::list<>, its location in memory never changes.
This makes a std::list<> ideal for storing vertices of an arbitrary n-ary
tree where a vertex contain pointers to its parent / children. These parent
/ child vertices need to stay put if we've got pointers to them somewhere!

Am I correct in my assertion?

Thanks,
Dave



Relevant Pages

  • Re: hacker challenge - traverse a list
    ... came from (a link to your parent) in the node. ... Fortunately the link holding the address of the child you are going to ... you can do a clever trick with moving pointers around that implicitly ... could do the trick, but again one needs to remember the "state" (number ...
    (comp.programming)
  • Re: reiser4 plugins
    ... > parent pointers starting from A. If you ever reach B, ... /nothing/ can touch the filesystem to do any change... ... And that means walking down to /each/ ...
    (Linux-Kernel)
  • Re: How to use std::sort() when my binary predicate is NOT transitive?
    ... However, that would require much code work, and need to handle ... child to the parent, there is no way to say if they ... element in the container and pointers in the nodes themselves. ... sorting algorithm) will make it difficult to keep those pointers correct. ...
    (microsoft.public.vc.language)
  • Re: Storing a tree in a std::list<>
    ... > just trees. ... problems) but still have the convenient use of pointers. ... and that node has pointers to its parent and children (which also ... By having the nodes in a std::list, I can destroy an ...
    (comp.lang.cpp)
  • Re: Object recreating itself as a different class type ?
    ... objects from parent to child objects, ... has the same structure as the parent, but the child has some more stuff. ... All pointers would simply keep pointing to the intermediate pointer ... I've seen this technique used to support lazy evaluation. ...
    (alt.comp.lang.borland-delphi)