For example exist linked list with thousands (maybe million) elements or very deep tree which some branches are very long and have only one child, but exists other short branches with many children. How process this lists and trees changing very deep recursion to iteration? I have
struct Node {
Node* next;
};
but also can exists other types and have more pointers:
struct Node1: public Node {
Node* next1;
Node* next2;
};
Now I want use recursion if have > 1 non empty pointers, but iterate over long series ..next->next->next->... I don't know which pointer will have long or short series.