interactive-coding-challenges/graphs_trees/bst/bst.py

19 lines
421 B
Python
Raw Normal View History

2015-08-02 05:44:14 +08:00
class Node(object):
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def insert(root, data):
if data <= root.data:
if root.left is None:
root.left = Node(data)
else:
insert(root.left, data)
else:
if root.right is None:
root.right = Node(data)
else:
insert(root.right, data)