class BinarySearchTree:
def __init__(self, value):
self.value = value
self.left_child = None
self.right_child = None
def insert_node(self, value):
if value <= self.value and self.left_child:
self.left_child.insert_node(value)
elif value <= self.value:
self.left_child = BinarySearchTree(value)
elif value > self.value and self.right_child:
self.right_child.insert_node(value)
else:
self.right_child = BinarySearchTree(value)
def in_order(self):
if self.left_child:
self.left_child.in_order()
print(self.value)
if self.right_child:
self.right_child.in_order()
def find_node(self, value):
if value < self.value and self.left_child:
return self.left_child.find_node(value)
if value > self.value and self.right_child:
return self.right_child.find_node(value)
return value == self.value
def find_min_value(self):
if self.left_child:
return self.left_child.find_min_value()
else:
return self.value
a_node = BinarySearchTree(5)
a_node.insert_node(4)
a_node.insert_node(6)
a_node.insert_node(1)
a_node.insert_node(7)
a_node.insert_node(3)
a_node.insert_node(2)
a_node.in_order()
print(a_node.find_node(14))
print(a_node.find_min_value())