Traversing without using recursion class