I have a problem where I need to find the longest path in a non-binary tree structure. I don't want to return the size of the longest path, I want to return the elements of the longest path in a vector
. For example, in a following picture 1 I want to find the longest path and store it in a vector
like this: {A,B,D,I,L}
. I think recursion is a way to go, but I just can't get the idea how to start building the code around the problem. I am storing the nodes in a following structures:
std::unordered_map<std::string ID, Node> Node_data_;
struct Node
{
std::string id;
Name name;
std::vector<Node*> children;
Town_info* master = nullptr;
};