Is there an efficient, practical way to iterate over a binary tree given the following constraints:
- You do not have control of the call stack, and thus may not use recursion. All state must live inside the iterator/range object, not on the stack.
- No heap allocations may be used anywhere in the algorithm.
- The tree may be immutable, and thus you cannot store iteration state inside it.
- You don't have parent pointers.
- The iterator/range struct must not be so large that it's completely unreasonable to pass to functions.
Edit:
- This is not homework. I actually am trying to design a library that builds binary trees on a second stack and makes lots of guarantees about heap allocations (or lack thereof).
- The trees are balanced. (They are AVL trees.)