14 template <
typename TType>
19 std::vector<std::unique_ptr<Node<TType>>>
_children;
89 template <
typename TType>
93 std::unique_ptr<Node<TType>> _root;
100 _root = std::make_unique<Node<TType>>(value);
119 return addChild(_root.get(), value);
128 if (_root !=
nullptr)
137 for (
const auto& child : node->
_children)
146 std::vector<TType> result;
155 result.push_back(node->
data);
156 for (
const auto& child : node->
_children)
166 if (_root !=
nullptr)
174 for (
const auto& child : node->
_children)
184 std::vector<TType> result;
194 for (
const auto& child : node->
_children)
197 result.push_back(node->
data);
200 template <
typename TResult>
206 std::vector<TResult> childResults;
210 for (
const auto& child : node->
_children)
211 childResults.push_back(postorderCompute<TResult>(child.get()));
void postorder(Node< TType > *node, std::vector< TType > &result)
void preorder(Node< TType > *node, std::function< void(TType)> &funct)
std::vector< TType > preorderValues()
Node< TType > * getRoot() const
void postorder(std::function< void(TType)> &funct)
Traverse the tree in postorder (children → parent).
Node< TType > * setRoot(TType value)
TResult postorderCompute(Node< TType > *node)
void postorder(Node< TType > *node, std::function< void(TType)> &funct)
Node< TType > * addChild(Node< TType > *parent, const TType &value)
std::vector< TType > postorderValues()
void preorder(Node< TType > *node, std::vector< TType > &result)
Node< TType > * addChildToRoot(const TType &value)
void preorder(std::function< void(TType)> &funct)
Traverse the tree in preorder (parent → children).
Node structure for an n-ary tree.
std::function< TType(std::vector< TType >)> parentFunct
void addChild(const TType &child)
Node< TType > * setParentFunct(std::function< TType(std::vector< TType >)> func)
std::vector< std::unique_ptr< Node< TType > > > _children