For Leetcode 7 and 8 - non-recursive tree traversal