On Mon, 02 Sep 2002 10:47:42 +0200, Matthias Kronenberger wrote:
You could chose to emulate such an tree using a std::multimap. Which maps the father vertex id to the child vertices. you can also specify your own ordering relation. To access all children is trivial, if you want to access all grandchilds and so own, you'd have to create a nice adapter class, that connects all children of children ranges together.
I thought of this, too, but then, there is a simpler emulation
using the property that an N-ary ordered tree has nodes with either
no child or exactly N childeren. This menas that we can number the
nodes of a complete tree by (if N=3)
level 0: 0
level 1: 1 2 3
level 2: 4 5 6 7 8 9 10 11 12
and so on. Very simple calculations then give the id numbers of all
children of a given parent, or the parent of a given child, and so
on. If the tree is not complete, some of the groups are missing, but
the same ordering can still be applied.
Putting this in a pair