How to print leaf nodes of binary tree without recursion

In the last article, you have learned how to print all leaf nodes of a binary tree in Java by using recursion and in this article, we'll solve the same problem without using recursion. Why should we do this? Well, it's a common pattern on programming job interview to solve the same problem using recursion and iteration. Since some problems are easy to solve using recursion e.g. tree based problems, tower of Hanoi, or Fibonacci series but their non-recursive solution is comparatively difficult, interviewer test candidates against this shift in the algorithm. If you have attended your computer science classes and enjoyed there, then you know that we can use Stack to convert a recursive algorithm to an iterative one. I'll use the same technique to print all leaf nodes of a binary tree without recursion.
Read more »