def all_nodes(root):
    """Return a list of all nodes of the tree, from left to right (iterative implementation)."""
    result = []
    path = [None]
    node = root
    while node is not None:
        if node.left is not None:
            path.append(node)
            node = node.left
        elif node.right is not None:
            result.append(node)
            node = node.right
        else:
            result.append(node)
            node = path.pop()
            if node is not None:
                result.append(node)
                node = node.right

    return result