java - Is there a way to create a unique variable with each recursion? -


is possible create variable unique level of recursion whatever happens remain way, regardless of every other recursive step? , can done in way can retrieve value in variable in each recursive step after recursion finished?

let me use example visualize problem. let's i've got tree. want record depth levels of every node, , organize nodes @ each depth level bundled in same array or list. i'll need different array/list each depth level.

i'm traversing tree recursively. @ beginning of each recursion, i'm creating new list. it's same line, every recursion creates list variable same name. processing node in depth x. add node list, proceed (recursively) child node @ depth x + 1. add child node new list. on , forth until nodes in tree belong list.

after recursion finished, expect have number of lists equal height of tree (1 list per depth, containing nodes in depth), , way access nodes in lists.

is possible?

store values in list, appending each new value list. index of value in list recursion depth @ value added.


Comments