Created
August 24, 2018 03:28
-
-
Save nooperpudd/1cb53d61ba8d805bea4903b9156956de to your computer and use it in GitHub Desktop.
ss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, info): | |
self.info = info | |
self.left = None | |
self.right = None | |
self.level = None | |
def __str__(self): | |
return str(self.info) | |
class BinarySearchTree: | |
def __init__(self): | |
self.root = None | |
def create(self, val): | |
if self.root == None: | |
self.root = Node(val) | |
else: | |
current = self.root | |
while True: | |
if val < current.info: | |
if current.left: | |
current = current.left | |
else: | |
current.left = Node(val) | |
break | |
elif val > current.info: | |
if current.right: | |
current = current.right | |
else: | |
current.right = Node(val) | |
break | |
else: | |
break | |
tree = BinarySearchTree() | |
t=7 | |
arr=[3 ,5, 2, 1, 4, 6, 7] | |
for i in range(t): | |
tree.create(arr[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment