An interesting question I came across recently:
Pb: Write a function to print binary tree in order, without using recursion. You are given a stack object, which has methods pop and push
If you are well versed in recursion, this problem may be tricky to think through at first.
Basically one needs to develop insight about a few things :
- The terminating condition.
- What to do once you have pop’d a node.
Code