Node[*Node][*Node][*Node][*Node][...][*Node] | | | | ... | | | | | V | | | V Node[*Node][*Node][...][*Node] | | V Node[*Node][*Node][*Node][*Node][...][*Node] | V Node[*Node][*Node][*Node][*Node][...][*Node] V Node[*Node][*Node][*Node][*Node][...][*Node] Node[*Node][*Node][*Node][*Node][...][*Node]
Each node would have it's own representative data such as name, state(e.g., expanded || collapsed, date of creation), as well as a collection of children.
For various reasons I attempted to accomplish this with a std::map rather than a std::vector, or similar. A vector may actually be more tractible, and appropreate for this task. In either case, I am at a loss for how to create such a recursive tree using the STL. Does anybody understand my objective? If so, do you know of an approach to solving this problem with an STL container?
The following will do it. I've used a list but a vector would also be
fine. I've put in a couple of examples of recursive algorithms. Note
that the tree need not actually be binary.
#include<iostream>
#include<list>
class tree {
public:
tree( double size ){
node_size = size;
}
void add_node( tree* b ){
subnodes.push_back( b );
}
double total_size(){
double size = node_size;
for( std::list