mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 03:18:02 +00:00
Simpilfied bst challenge.
This commit is contained in:
18
graphs_trees/bst/bst.py
Normal file
18
graphs_trees/bst/bst.py
Normal file
@@ -0,0 +1,18 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user