Implement pre-order traversal with iterator