Tree datastructures: Difference between revisions

m
C++ - use list instead of vector in nest_tree so that adding a child doesn't invalidate references to existing children
(Added C++ solution)
m (C++ - use list instead of vector in nest_tree so that adding a child doesn't invalidate references to existing children)
Line 42:
<lang cpp>#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>
Line 64 ⟶ 65:
return name_;
}
const std::vectorlist<nest_tree>& children() const {
return children_;
}
Line 78 ⟶ 79:
}
std::string name_;
std::vectorlist<nest_tree> children_;
};
 
Line 120 ⟶ 121:
nest_tree n("RosettaCode");
auto& child1 = n.add_child("rocks");
auto& child2 = n.add_child("mocks");
child1.add_child("code");
child1.add_child("comparison");
child1.add_child("wiki");
auto& child2 = n.add_child("mocks");
child2.add_child("trolling");
1,777

edits