Something I have written in C++ to traverse a tree without using recursion