(Change thanks to Nikos Karampatziakis)
Switched the recursion in the tree traversal function to std::stack in order to prevent stack buffer overflow.