class Node:

    def update(self):
        self.inorder_iter = iter(self.inorderTraversal(self))

    def __init__(self, data):

        self.left = None
        self.right = None
        self.data = data

        self.update()

    def insert(self, data):
# Compare the new value with the parent node
        if self.data:
            if data < self.data:
                if self.left is None:
                    self.left = Node(data)
                else:
                    self.left.insert(data)
            elif data > self.data:
                if self.right is None:
                    self.right = Node(data)
                else:
                    self.right.insert(data)
        else:
            self.data = data

        self.update()

    def PrintTree(self):
        if self.left:
            self.left.PrintTree()
        print( self.data),
        if self.right:
            self.right.PrintTree()

    def inorderTraversal(self, root):
        res = []
        if root:
            res = self.inorderTraversal(root.left)
            res.append(root.data)
            res = res + self.inorderTraversal(root.right)
        return res

    def __iter__(self):
        return self

    def __next__(self):
        return next(self.inorder_iter)


root= Node(12)
root.insert(6)
root.insert(14)
root.insert(3)
root.insert(16)
print(*root.inorderTraversal(root))

