Is it possible to create a variable that is unique to that level of recursion so that whatever happens to it will remain that way, regardless of every other recursive step? And can this be done in a way that I can retrieve the value in the variable in each recursive step after the recursion is finished?
Let me use an example to visualize the problem. Let's say I've got a tree. I want to record the depth levels of every node, and organize it so that all the nodes at each depth level are bundled in the same array or list. So I'll need a different array/list for each depth level.
I'm traversing the tree recursively. At the beginning of each recursion, I'm creating a new list. It's the same line, so every recursion creates a list variable with the same name. I am processing a node in depth X. I add this node to the list, then proceed (recursively) to a child node at depth X + 1. I add this child node to a new list. So on and so forth until all the nodes in the tree belong to some list.
After the recursion is finished, I expect to have a number of lists equal to the height of the tree (1 list per depth, containing all the nodes in that depth), and a way to access all the nodes in all the lists.
Is this possible?