from implementations.tree import BinaryTreeNode


def invert_tree(tree):
    if not tree:
        return tree

    tmp = tree.left
    tree.left = tree.right
    tree.right = tmp

    if tree.left:
        invert_tree(tree.left)
    if tree.right:
        invert_tree(tree.right)


if __name__ == '__main__':
    tree = BinaryTreeNode(4)
    tree.left = BinaryTreeNode(2)
    tree.left.left = BinaryTreeNode(1)
    tree.right = BinaryTreeNode(7)
    tree.right.left = BinaryTreeNode(6)
    tree.right.right = BinaryTreeNode(9)
    invert_tree(tree)
    print tree
    print tree.left, tree.right
    print tree.left.left, tree.left.right, '\t', tree.right.left, tree.right.right
