Jeanne Boyarsky wrote:Sebastian,
sometimes a recursive approach is clearer. Especially when doing tree navigation.
leroy tsruya wrote:My question, is it the correct way to do it? or is it a better way to do it? (it must be recursive).
Sebastian Janisch wrote:I found a loop in your code and I'm asking myself if it really has to be there ? Since the idea of the recursive approach is not to use loops..
Sebastian Janisch wrote:first of all, in most cases it really doesn't make sense to use an recursive approach over an iterative one. The reason is simple. Even though it is a more elegant approach, you always have the risk of running into an StackOverflowError. Also, with every subsequent recursion, another frame goes on the stack, which is not really a performance hit.
leroy tsruya wrote:I try to rewrite my method without this while loop, but i cannot.