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::
return children_;
}
Line 78 ⟶ 79:
}
std::string name_;
std::
};
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");
|