Hello all,
Suppose you need to create an n-ary tree in memory. I'm trying to come up
with an elegant scheme to have all of the memory for the tree deallocated
automatically. i.e. I don't want to have to do any dynamic memory
management myself. However, I don't want to go through all sorts of
ridiculous contortions either to avoid the use of pointers / dynamic memory
management. The solution should cost less than what I'm trying to avoid!
If I represent a node as a std::vector of smart pointers to nodes (and of
course the ancillary data held at the node), it would seem that the root
node being destroyed would result in the whole tree of arbitrary width /
depth / branching characteristic being destroyed.
It would seem that this scheme would be a good candidate for being made
generic (the generic parameterization would be for the user-defined
ancillary data associated with each node).
Is there anything wrong with my scheme? Can anybody offer a superior
alternative?
Thanks,
Dave