from algorithms_and_data_structures.trees.node import Node


def check_valid_value(value):
    if type(value) not in [int, float]:
        raise TypeError(f'Invalid value type {value}: {type(value)}')


def insert(root_node, value):
    """Inserts a new node to a binary  Tree, given the root node of this binary tree."""
    check_valid_value(value)
    if root_node is None:
        return Node(value)
    else:
        if root_node.value == value:
            return root_node
        elif root_node.value < value:
            root_node.right = insert(root_node.right, value)
        else:
            root_node.left = insert(root_node.left, value)
    return root_node


def print_tree_inorder(root_node):
    """Prints the binary tree in order. (Left node, Root node, Right node)"""
    if root_node:
        print_tree_inorder(root_node.left)
        print(root_node.value)
        print_tree_inorder(root_node.right)
from algorithms_and_data_structures.trees.node import Node


def check_valid_value(value):
    if type(value) not in [int, float]:
        raise TypeError(f'Invalid value type {value}: {type(value)}')


def insert(root_node, value):
    """Inserts a new node to a binary  Tree, given the root node of this binary tree."""
    check_valid_value(value)
    if root_node is None:
        return Node(value)
    else:
        if root_node.value == value:
            return root_node
        elif root_node.value < value:
            root_node.right = insert(root_node.right, value)
        else:
            root_node.left = insert(root_node.left, value)
    return root_node


def print_tree_inorder(root_node):
    """Prints the binary tree in order. (Left node, Root node, Right node)"""
    if root_node:
        print_tree_inorder(root_node.left)
        print(root_node.value)
        print_tree_inorder(root_node.right)
Inserts a new node to a binary  Tree, given the root node of this binary tree. Prints the binary tree in order. (Left node, Root node, Right node)